Skip to content
Snippets Groups Projects
Commit 9ff793d7 authored by Cam Saül's avatar Cam Saül
Browse files

Merge pull request #514 from metabase/qp_cleanup_2000

A bit of cleanup in the QP.
parents 11368504 0233dc63
No related branches found
No related tags found
No related merge requests found
......@@ -18,15 +18,10 @@
expand
get-special-column-info
preprocess-cumulative-sum
preprocess-structured
remove-empty-clauses)
preprocess-structured)
;; # CONSTANTS
(def ^:const empty-response
"An empty response dictionary to return when there's no query to run."
{:rows [], :columns [], :cols []})
(def ^:const max-result-rows
"Maximum number of rows the QP should ever return."
10000)
......@@ -71,7 +66,6 @@
;; Functions that take place before expansion
;; These functions expect just the :query subdictionary (TODO -- these need to be changed to use to expanded query at some point
(update-in query [:query] #(->> %
remove-empty-clauses
add-implicit-breakout-order-by
add-implicit-limit
add-implicit-fields))
......@@ -86,27 +80,6 @@
;; ## PREPROCESSOR FNS
;; ### REMOVE-EMPTY-CLAUSES
(def ^:private ^:const clause->empty-forms
"Clause values that should be considered empty and removed during preprocessing."
{:breakout #{[nil]}
:filter #{[nil nil]}})
(defn remove-empty-clauses
"Remove all QP clauses whose value is:
1. is `nil`
2. is an empty sequence (e.g. `[]`)
3. matches a form in `clause->empty-forms`"
[query]
(->> query
(map (fn [[clause clause-value]]
(when (and clause-value
(or (not (sequential? clause-value))
(seq clause-value)))
(when-not (contains? (clause->empty-forms clause) clause-value)
[clause clause-value]))))
(into {})))
;; ### ADD-IMPLICIT-BREAKOUT-ORDER-BY
......
......@@ -79,6 +79,12 @@
;; ## -------------------- Expansion - Impl --------------------
(defn- non-empty-clause? [clause]
(and clause
(or (not (sequential? clause))
(and (seq clause)
(every? identity clause)))))
(defn- parse [query-dict]
(update-in query-dict [:query] #(-<> (assoc %
:aggregation (parse-aggregation (:aggregation %))
......@@ -88,7 +94,7 @@
:order_by (parse-order-by (:order_by %)))
(set/rename-keys <> {:order_by :order-by
:source_table :source-table})
(m/filter-vals identity <>))))
(m/filter-vals non-empty-clause? <>))))
(def ^:private ^:dynamic *field-ids*
"Bound to an atom containing a set when a parsing function is ran"
......@@ -210,10 +216,7 @@
"Convenience for writing a parser function, i.e. one that pattern-matches against a lone argument."
[fn-name & match-forms]
`(defn ~(vary-meta fn-name assoc :private true) [form#]
(when (and form#
(or (not (sequential? form#))
(and (seq form#)
(every? identity form#))))
(when (non-empty-clause? form#)
(match form#
~@match-forms))))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment