Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
9ff793d7
Commit
9ff793d7
authored
9 years ago
by
Cam Saül
Browse files
Options
Downloads
Plain Diff
Merge pull request #514 from metabase/qp_cleanup_2000
A bit of cleanup in the QP.
parents
11368504
0233dc63
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/driver/query_processor.clj
+1
-28
1 addition, 28 deletions
src/metabase/driver/query_processor.clj
src/metabase/driver/query_processor/expand.clj
+8
-5
8 additions, 5 deletions
src/metabase/driver/query_processor/expand.clj
with
9 additions
and
33 deletions
src/metabase/driver/query_processor.clj
+
1
−
28
View file @
9ff793d7
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
src/metabase/driver/query_processor/expand.clj
+
8
−
5
View file @
9ff793d7
...
...
@@ -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
))))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment