 {:base_type :IntegerField, :special_type :category, :id nil, :table_id nil, :description nil, :extra_info {}, :target nil, :name "sum"}
 
 (defn- aggregate-fieldo [{{ag-type :aggregation-type, ag-field :field} :aggregation} field]
-  (all (membero ag-type [:count :avg :sum :stddev])
-       (if-not ag-field
-         (do (assert (= ag-type :count))
-             (== field {:base-type    :IntegerField
-                        :field-name   :count
-                        :special-type :number}))
-         (fresh [field-name]
-           (== field (assoc (select-keys ag-field [:base-type :special-type])
-                            :field-name field-name))
-           (membero field-name [:count :avg :sum :stddev])
-           (conde
-            ((== ag-type field-name))
-            ((== ag-type :distinct) (== field-name :count)))))))
+  (or (when (contains? #{:count :avg :sum :stddev} ag-type)
+        (if-not ag-field
+          (do (assert (= ag-type :count))
+              (== field {:base-type    :IntegerField
+                         :field-name   :count
+                         :special-type :number}))
+          (fresh [field-name]
+            (== field (assoc (select-keys ag-field [:base-type :special-type])
+                             :field-name field-name))
+            (membero field-name [:count :avg :sum :stddev])
+            (conde
+             ((== ag-type field-name))
+             ((== ag-type :distinct) (== field-name :count))))))
+      fail))
 
 (defn- valid-nameo [{:keys [result-keys]} field]
   (fresh [field-name]

   ((fields-sorted-by-nameo query f1 f2))))

(defn- resolve+order-cols [query]
  (let [num-cols (count (:result-keys query))
        cols     (vec (lvars num-cols))]
    (first (run 1 [q]

                       (map format-col)
                       add-fields-extra-info)
          columns (mapv :name cols)]
      {:cols    cols
       :columns columns
       :rows    (for [row results]
                  (mapv row columns))})))

(require 'metabase.driver)

