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
88dc244d
Commit
88dc244d
authored
6 years ago
by
Simon Belak
Browse files
Options
Downloads
Patches
Plain Diff
Make normalization aware of share
parent
41f95b1f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/mbql/normalize.clj
+44
-41
44 additions, 41 deletions
src/metabase/mbql/normalize.clj
test/metabase/query_processor_test/share_test.clj
+9
-0
9 additions, 0 deletions
test/metabase/query_processor_test/share_test.clj
with
53 additions
and
41 deletions
src/metabase/mbql/normalize.clj
+
44
−
41
View file @
88dc244d
...
...
@@ -296,6 +296,47 @@
[
:field-id
field
]
field
))
(
defn-
canonicalize-filter
[
filter-clause
]
(
mbql.u/replace
filter-clause
seq?
(
recur
(
vec
&
match
))
;; for `and`/`or`/`not` compound filters, recurse on the arg(s), then simplify the whole thing
[(
filter-name
:guard
#
{
:and
:or
:not
})
&
args
]
(
mbql.u/simplify-compound-filter
(
vec
(
cons
filter-name
;; we need to canonicalize any other mbql clauses that might show up in
;; args like datetime-field here because simplify-compund-filter validates
;; its output :(
(
map
(
comp
canonicalize-mbql-clauses
canonicalize-filter
)
args
))))
[(
filter-name
:guard
#
{
:starts-with
:ends-with
:contains
:does-not-contain
})
field
arg
options
]
[
filter-name
(
wrap-implicit-field-id
field
)
arg
options
]
[(
filter-name
:guard
#
{
:starts-with
:ends-with
:contains
:does-not-contain
})
field
arg
]
[
filter-name
(
wrap-implicit-field-id
field
)
arg
]
[
:inside
field-1
field-2
&
coordinates
]
(
vec
(
concat
[
:inside
(
wrap-implicit-field-id
field-1
)
(
wrap-implicit-field-id
field-2
)]
coordinates
))
;; if you put a `:datetime-field` inside a `:time-interval` we should fix it for you
[
:time-interval
[
:datetime-field
field
_
]
&
args
]
(
recur
(
apply
vector
:time-interval
field
args
))
;; all the other filter types have an implict field ID for the first arg
;; (e.g. [:= 10 20] gets canonicalized to [:= [:field-id 10] 20]
[(
filter-name
:guard
#
{
:=
:!=
:<
:<=
:>
:>=
:is-null
:not-null
:between
:inside
:time-interval
})
field
&
more
]
(
apply
vector
filter-name
(
wrap-implicit-field-id
field
)
more
)
;; don't wrap segment IDs in `:field-id`
[
:segment
_
]
&
match
_
(
throw
(
IllegalArgumentException.
(
str
(
tru
"Illegal filter clause: {0}"
filter-clause
))))))
(
defn-
canonicalize-aggregation-subclause
"Remove `:rows` type aggregation (long-since deprecated; simpliy means no aggregation) if present, and wrap
`:field-ids` where appropriate."
...
...
@@ -323,6 +364,9 @@
[
:metric
_
]
&
match
[
:share
pred
]
[
:share
(
canonicalize-filter
pred
)]
;; something with an arg like [:sum [:field-id 41]]
[
ag-type
field
]
[
ag-type
(
wrap-implicit-field-id
field
)]))
...
...
@@ -360,47 +404,6 @@
(
map
canonicalize-aggregation-subclause
)
(
filterv
identity
)))
(
defn-
canonicalize-filter
[
filter-clause
]
(
mbql.u/replace
filter-clause
seq?
(
recur
(
vec
&
match
))
;; for `and`/`or`/`not` compound filters, recurse on the arg(s), then simplify the whole thing
[(
filter-name
:guard
#
{
:and
:or
:not
})
&
args
]
(
mbql.u/simplify-compound-filter
(
vec
(
cons
filter-name
;; we need to canonicalize any other mbql clauses that might show up in
;; args like datetime-field here because simplify-compund-filter validates
;; its output :(
(
map
(
comp
canonicalize-mbql-clauses
canonicalize-filter
)
args
))))
[(
filter-name
:guard
#
{
:starts-with
:ends-with
:contains
:does-not-contain
})
field
arg
options
]
[
filter-name
(
wrap-implicit-field-id
field
)
arg
options
]
[(
filter-name
:guard
#
{
:starts-with
:ends-with
:contains
:does-not-contain
})
field
arg
]
[
filter-name
(
wrap-implicit-field-id
field
)
arg
]
[
:inside
field-1
field-2
&
coordinates
]
(
vec
(
concat
[
:inside
(
wrap-implicit-field-id
field-1
)
(
wrap-implicit-field-id
field-2
)]
coordinates
))
;; if you put a `:datetime-field` inside a `:time-interval` we should fix it for you
[
:time-interval
[
:datetime-field
field
_
]
&
args
]
(
recur
(
apply
vector
:time-interval
field
args
))
;; all the other filter types have an implict field ID for the first arg
;; (e.g. [:= 10 20] gets canonicalized to [:= [:field-id 10] 20]
[(
filter-name
:guard
#
{
:=
:!=
:<
:<=
:>
:>=
:is-null
:not-null
:between
:inside
:time-interval
})
field
&
more
]
(
apply
vector
filter-name
(
wrap-implicit-field-id
field
)
more
)
;; don't wrap segment IDs in `:field-id`
[
:segment
_
]
&
match
_
(
throw
(
IllegalArgumentException.
(
str
(
tru
"Illegal filter clause: {0}"
filter-clause
))))))
(
defn-
canonicalize-order-by
"Make sure order by clauses like `[:asc 10]` get `:field-id` added where appropriate, e.g. `[:asc [:field-id 10]]`"
[
clauses
]
...
...
This diff is collapsed.
Click to expand it.
test/metabase/query_processor_test/share_test.clj
+
9
−
0
View file @
88dc244d
...
...
@@ -17,6 +17,15 @@
ffirst
double
))
;; Test normalization
(
datasets/expect-with-drivers
(
non-timeseries-drivers-with-feature
:basic-aggregations
)
0.94
(
->>
{
:aggregation
[[
"share"
[
"<"
[
"field-id"
(
data/id
:venues
:price
)]
4
]]]}
(
data/run-mbql-query
venues
)
rows
ffirst
double
))
(
datasets/expect-with-drivers
(
non-timeseries-drivers-with-feature
:basic-aggregations
)
0.17
(
->>
{
:aggregation
[[
:share
[
:and
[
:<
[
:field-id
(
data/id
:venues
:price
)]
4
]
...
...
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