             [metabase.models.field :refer [Field field->fk-table]]))
 
 (declare add-implicit-breakout-order-by
+         add-implicit-limit
          get-special-column-info
          preprocess-cumulative-sum
          preprocess-structured

  (let [preprocessed-query (update-in query [:query] #(->> %
                                                           remove-empty-clauses
                                                           add-implicit-breakout-order-by
                                                           preprocess-cumulative-sum))]
    (when-not *disable-qp-logging*
      (log/debug (colorize.core/cyan "\n******************** PREPROCESSED: ********************\n"

                         [field-id "ascending"]))
                 (apply conj (or order-by-subclauses []))
                 (assoc query :order_by)))))


;;; ### ADD-IMPLICIT-LIMIT

(defn add-implicit-limit
  "Add an implicit limit clause to queries with `rows` aggregations."
  [{:keys [limit aggregation] :as query}]
  (if (and (= aggregation ["rows"])
           (not limit))
    (assoc query :limit max-result-rows)
    query))


;; ### PREPROCESS-CUMULATIVE-SUM
