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
d956eee4
Commit
d956eee4
authored
9 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
Add implicit fields clause to "rows" aggregation queries
parent
e392bc97
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/driver/query_processor.clj
+18
-1
18 additions, 1 deletion
src/metabase/driver/query_processor.clj
test/metabase/driver/query_processor_test.clj
+23
-1
23 additions, 1 deletion
test/metabase/driver/query_processor_test.clj
with
41 additions
and
2 deletions
src/metabase/driver/query_processor.clj
+
18
−
1
View file @
d956eee4
...
...
@@ -8,6 +8,7 @@
(
declare
add-implicit-breakout-order-by
add-implicit-limit
add-implicit-fields
get-special-column-info
preprocess-cumulative-sum
preprocess-structured
...
...
@@ -51,6 +52,7 @@
remove-empty-clauses
add-implicit-breakout-order-by
add-implicit-limit
add-implicit-fields
preprocess-cumulative-sum
))]
(
when-not
*disable-qp-logging*
(
log/debug
(
colorize.core/cyan
"\n******************** PREPROCESSED: ********************\n"
...
...
@@ -102,7 +104,7 @@
;;; ### ADD-IMPLICIT-LIMIT
(
defn
add-implicit-limit
"Add an implicit limit clause to queries with `rows` aggregations."
"Add an implicit
`
limit
`
clause to queries with `rows` aggregations."
[{
:keys
[
limit
aggregation
]
:as
query
}]
(
if
(
and
(
=
aggregation
[
"rows"
])
(
not
limit
))
...
...
@@ -110,6 +112,21 @@
query
))
;;; ### ADD-IMPLICIT-FIELDS
(
defn
add-implicit-fields
"Add an implicit `fields` clause to queries with `rows` aggregations."
[{
:keys
[
fields
aggregation
source_table
]
:as
query
}]
(
if
(
or
(
not=
aggregation
[
"rows"
])
fields
)
;; If we're not doing a "rows" aggregation or the fields clause was specified return the query as-is
query
;; Otherwise we need to look up the Fields for the Table in question so we don't return ones that are supposed to be hidden
(
let
[
fields
(
sel
:many
:id
Field
:table_id
source_table,
:active
true,
:preview_display
true,
:field_type
[
not=
"sensitive"
])]
(
assoc
query
:fields
fields
))))
;; ### PREPROCESS-CUMULATIVE-SUM
(
defn
preprocess-cumulative-sum
...
...
This diff is collapsed.
Click to expand it.
test/metabase/driver/query_processor_test.clj
+
23
−
1
View file @
d956eee4
...
...
@@ -4,7 +4,8 @@
[
metabase.db
:refer
:all
]
[
metabase.driver
:as
driver
]
[
metabase.driver.query-processor
:refer
:all
]
(
metabase.models
[
table
:refer
[
Table
]])
(
metabase.models
[
field
:refer
[
Field
]]
[
table
:refer
[
Table
]])
[
metabase.test.data.datasets
:as
datasets
:refer
[
*dataset*
]]))
;; ## Dataset-Independent Data Fns
...
...
@@ -706,3 +707,24 @@
:aggregation
[
"stddev"
(
id
:venues
:category_id
)]
:breakout
[(
id
:venues
:price
)]
:order_by
[[[
"aggregation"
0
]
"descending"
]]})
;;; ### make sure that rows where preview_display = false don't get displayed
(
datasets/expect-with-all-datasets
[(
set
(
->columns
"category_id"
"name"
"latitude"
"id"
"longitude"
"price"
))
(
set
(
->columns
"category_id"
"name"
"latitude"
"id"
"longitude"
))
(
set
(
->columns
"category_id"
"name"
"latitude"
"id"
"longitude"
"price"
))]
(
let
[
get-col-names
(
fn
[]
(
->
(
driver/process-query
{
:database
(
db-id
)
:type
"query"
:query
{
:aggregation
[
"rows"
]
:source_table
(
id
:venues
)
:order_by
[[(
id
:venues
:id
)
"ascending"
]]
:limit
1
}})
:data
:columns
set
))]
[(
get-col-names
)
(
do
(
upd
Field
(
id
:venues
:price
)
:preview_display
false
)
(
get-col-names
))
(
do
(
upd
Field
(
id
:venues
:price
)
:preview_display
true
)
(
get-col-names
))]))
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