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
ffc6e31f
Commit
ffc6e31f
authored
9 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
Generic SQL formatting for fields / values from expanded query
parent
c082bf93
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/generic_sql/query_processor.clj
+19
-16
19 additions, 16 deletions
src/metabase/driver/generic_sql/query_processor.clj
src/metabase/driver/query_processor/expand.clj
+5
-3
5 additions, 3 deletions
src/metabase/driver/query_processor/expand.clj
with
24 additions
and
19 deletions
src/metabase/driver/generic_sql/query_processor.clj
+
19
−
16
View file @
ffc6e31f
...
...
@@ -88,14 +88,19 @@
(
extend-protocol
IGenericSQLFormattable
Field
(
formatted
[{
:keys
[
field-name
base-type-special-type
]}]
;; TODO
(
keyword
field-name
))
(
formatted
[{
:keys
[
field-name
base-type
special-type
]}]
;; TODO - add Table names
(
cond
(
contains?
#
{
:DateField
:DateTimeField
}
base-type
)
`
(
raw
~
(
format
"CAST(\"%s\" AS DATE)"
field-name
))
(
=
special-type
:timestamp_seconds
)
`
(
raw
~
((
:cast-timestamp-seconds-field-to-date-fn
qp/*driver*
)
field-name
))
(
=
special-type
:timestamp_milliseconds
)
`
(
raw
~
((
:cast-timestamp-milliseconds-field-to-date-fn
qp/*driver*
)
field-name
))
:else
(
keyword
field-name
)))
Value
(
formatted
[{
:keys
[
value
base-type
special-type
]}]
;; TODO
value
))
(
formatted
[{
:keys
[
value
]}]
instance?
(
if-not
(
instance?
java.util.Date
value
)
value
`
(
raw
~
(
format
"CAST('%s' AS DATE)"
(
.toString
^
java.util.Date
value
))))))
(
defmethod
apply-form
:aggregation
[[
_
{
:keys
[
aggregation-type
field
]}]]
...
...
@@ -114,16 +119,14 @@
:sum
`
(
aggregate
(
~
'sum
~
field
)
:sum
)))))
;; TODO
(
defmethod
apply-form
:breakout
[[
_
field-ids
]]
(
let
[
;; Group by all the breakout fields
field-names
(
map
field-id->kw
field-ids
)
;; Add fields form only for fields that weren't specified in :fields clause -- we don't want to include it twice, or korma will barf
fields-not-in-fields-clause-names
(
->>
field-ids
(
filter
(
partial
(
complement
contains?
)
(
set
(
:fields
(
:query
qp/*query*
)))))
(
map
field-id->kw
))]
`
[(
group
~@
field-names
)
(
fields
~@
fields-not-in-fields-clause-names
)]))
(
defmethod
apply-form
:breakout
[[
_
fields
]]
`
[
;; Group by all the breakout fields
(
group
~@
(
map
formatted
fields
))
;; Add fields form only for fields that weren't specified in :fields clause -- we don't want to include it twice, or korma will barf
(
fields
~@
(
->>
fields
(
filter
(
partial
(
complement
contains?
)
(
set
(
:fields
(
:query
qp/*query*
)))))
(
map
formatted
)))])
(
defmethod
apply-form
:fields
[[
_
fields
]]
...
...
This diff is collapsed.
Click to expand it.
src/metabase/driver/query_processor/expand.clj
+
5
−
3
View file @
ffc6e31f
...
...
@@ -40,6 +40,7 @@
[
string
:as
s
]
[
walk
:as
walk
])
[
medley.core
:as
m
]
[
swiss.arrows
:refer
[
-<>
]]
[
metabase.db
:refer
[
sel
]]
[
metabase.models.field
:as
field
]
[
metabase.util
:as
u
])
...
...
@@ -72,13 +73,14 @@
;; ## -------------------- Public Interface --------------------
(
defn-
parse
[
query-dict
]
(
update-in
query-dict
[
:query
]
#
(
->>
(
assoc
%
(
update-in
query-dict
[
:query
]
#
(
-<>
(
set/rename-keys
%
{
:order_by
:order-by
})
(
assoc
<>
:aggregation
(
parse-aggregation
(
:aggregation
%
))
:breakout
(
parse-breakout
(
:breakout
%
))
:fields
(
parse-fields
(
:fields
%
))
:filter
(
parse-filter
(
:filter
%
))
:order-by
(
parse-order-by
(
:order
_
by
%
)))
(
m/filter-vals
identity
))))
:order-by
(
parse-order-by
(
:order
-
by
%
)))
(
m/filter-vals
identity
<>
))))
(
defn
expand
"Expand a query-dict."
...
...
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