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
b8e5b17c
Commit
b8e5b17c
authored
9 years ago
by
Cam Saül
Browse files
Options
Downloads
Patches
Plain Diff
squash! Rework the way field flattening happens in annotate
parent
121f5928
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/metabase/driver/query_processor/annotate.clj
+16
-12
16 additions, 12 deletions
src/metabase/driver/query_processor/annotate.clj
with
16 additions
and
12 deletions
src/metabase/driver/query_processor/annotate.clj
+
16
−
12
View file @
b8e5b17c
...
...
@@ -44,7 +44,7 @@
(
assoc
field
:field-name
(
keyword
(
apply
str
(
->>
(
rest
(
i/qualified-name-components
field
))
(
interpose
"."
))))))
(
defn
-
collect-fields
(
defn
collect-fields
"Return a sequence of all the `Fields` inside THIS, recursing as needed for collections.
For maps, add or `conj` to property `:path`, recording the keypath used to reach each `Field.`
...
...
@@ -53,16 +53,14 @@
(collect-fields {:a {:name \"id\", ...}) -> [{:name \"id\", :path [:a], ...}]"
[
this
]
(
condp
instance?
this
clojure.lang.IPersistentMap
(
for
[[
k
v
]
(
seq
this
)
field
(
collect-fields
v
)]
(
update
field
:path
conj
k
))
clojure.lang.Sequential
(
mapcat
collect-fields
this
)
;; For a DateTimeField we'll flatten it back into regular Field but include the :unit info for the frontend.
;; Recurse so it is otherwise handled normally
metabase.driver.query_processor.interface.DateTimeField
(
let
[{
:keys
[
field
unit
]}
this
]
(
recur
(
assoc
field
:unit
unit
)))
metabase.driver.query_processor.interface.Field
(
if-let
[
{
:keys
[
parent
]}
this
]
(
if-let
[
parent
(
:
parent
this
)
]
;; Nested Mongo fields come back inside of their parent when you specify them in the fields clause
;; e.g. (Q fields venue...name) will return rows like {:venue {:name "Kyle's Low-Carb Grill"}}
;; Until we fix this the right way we'll just include the parent Field in the :query-fields list so the pattern
...
...
@@ -70,15 +68,21 @@
[
this
parent
]
[
this
])
;; For a DateTimeField we'll flatten it back into regular Field but include the :unit info for the frontend
metabase.driver.query_processor.interface.DateTimeField
(
recur
(
assoc
(
:field
this
)
:unit
(
:unit
this
)))
clojure.lang.IPersistentMap
(
for
[[
k
v
]
(
seq
this
)
field
(
collect-fields
v
)
:when
field
]
(
update
field
:path
conj
k
))
clojure.lang.Sequential
(
mapcat
collect-fields
this
)
nil
))
(
defn-
flatten-fields
"Flatten a group of fields, keeping those which are more important when duplicates exist."
[
fields
]
{
:pre
[(
every?
identity
fields
)]}
(
let
[
path-importance
(
fn
[{[
k
]
:path
}]
(
cond
(
=
k
:breakout
)
0
; lower number = higher importance, because `sort` is ascending
...
...
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