   (or (not (:errors query))
       (zero? (reduce + (map count (:errors query))))))
 
-(defn valid-field? [metadata slice field]
+(defn valid-field? [{:keys [metadata slice]} field]
   (let [identifier-regex-str (.pattern parser/identifier-regex)
         concept-regex (re-pattern (str "__(" identifier-regex-str ")\\.(" identifier-regex-str ")"))
         [concept property] (if-let [match (re-matches concept-regex field)]

          dimensions (:dimensions slicedef)]
      (-> query
          (assoc :errors {})
          (validate-select metadata slice)
          (validate-group metadata slice dimensions)
          validate-where
          validate-order-by
          validate-limit

    query
    (add-error query :group "You must have a select clause to use grouping.")))

(defn- convert-group-to-mongo-form
  [group]
  (if (coll? group)
    (str "__" (str/join "." (map name group)))
    group))

(defn- validate-group-fields
  [query group]
  (let [group (map convert-group-to-mongo-form group)]
    (reduce #(validate-field %1 :group %2) query group)))

(defn- validate-group-only-group-dimensions
  [{:keys [slicedef] :as query} group]
  (let [dimensions (set (:dimensions slicedef))]
    (reduce
     (fn [query field]
       (let [field (name field)]
