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
fca0c77a
Commit
fca0c77a
authored
9 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
more test fixes
parent
7d62c65e
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/driver/generic_sql/query_processor.clj
+28
-28
28 additions, 28 deletions
src/metabase/driver/generic_sql/query_processor.clj
test/metabase/driver/query_processor_test.clj
+0
-16
0 additions, 16 deletions
test/metabase/driver/query_processor_test.clj
with
28 additions
and
44 deletions
src/metabase/driver/generic_sql/query_processor.clj
+
28
−
28
View file @
fca0c77a
...
...
@@ -10,6 +10,7 @@
[
util
:refer
:all
])
[
metabase.util
:as
u
])
(
:import
(
metabase.driver.query_processor.expand
Field
OrderByAggregateField
Value
)))
...
...
@@ -95,9 +96,19 @@
(
=
special-type
:timestamp_milliseconds
)
`
(
raw
~
((
:cast-timestamp-milliseconds-field-to-date-fn
qp/*driver*
)
field-name
))
:else
(
keyword
field-name
)))
;; e.g. the ["aggregation" 0] fields we allow in order-by
OrderByAggregateField
(
formatted
[
_
]
(
let
[{
:keys
[
aggregation-type
]}
(
:aggregation
(
:query
qp/*query*
))]
; determine the name of the aggregation field
`
(
raw
~
(
case
aggregation-type
:avg
"\"avg\""
:count
"\"count\""
:distinct
"\"count\""
:stddev
"\"stddev\""
:sum
"\"sum\""
))))
Value
(
formatted
[{
:keys
[
value
]}]
instance?
(
if-not
(
instance?
java.util.Date
value
)
value
`
(
raw
~
(
format
"CAST('%s' AS DATE)"
(
.toString
^
java.util.Date
value
))))))
...
...
@@ -111,11 +122,12 @@
;; aggregation clauses with a Field
(
let
[
field
(
formatted
field
)]
(
case
aggregation-type
:avg
`
(
aggregate
(
~
'avg
~
field
)
:avg
)
:count
`
(
aggregate
(
~
'count
~
field
)
:count
)
:distinct
`
(
aggregate
(
~
'count
(
sqlfn
:DISTINCT
~
field
))
:count
)
:stddev
`
(
fields
[(
sqlfn
:stddev
~
field
)
:stddev
])
:sum
`
(
aggregate
(
~
'sum
~
field
)
:sum
)))))
:avg
`
(
aggregate
(
~
'avg
~
field
)
:avg
)
:count
`
(
aggregate
(
~
'count
~
field
)
:count
)
:distinct
`
(
aggregate
(
~
'count
(
sqlfn
:DISTINCT
~
field
))
:count
)
:stddev
`
(
fields
[(
sqlfn
:stddev
~
field
)
:stddev
])
:sum
`
(
aggregate
(
~
'sum
~
field
)
:sum
)
:cumulative-sum
nil
))))
; nothing to do here - this is implemented in post-processing
(
defmethod
apply-form
:breakout
[[
_
fields
]]
...
...
@@ -132,21 +144,16 @@
`
(
fields
~@
(
map
formatted
fields
)))
;; (fn [v]
;; (if-not (or (= (type v) java.sql.Date)
;; (= (type v) java.util.Date)) v
;; `(raw ~(format "CAST('%s' AS DATE)" (.toString ^java.sql.Date v)))))
(
defn-
filter-subclause->predicate
"Given a filter SUBCLAUSE, return a Korma filter predicate form for use in korma `where`."
[{
:keys
[
filter-type
]
,
:as
filter
}]
(
if
(
=
filter-type
:inside
)
;;
inside
filter subclause
(
let
[{
:keys
[
lat
lon
]}
:
filter
]
`
(
~
'and
{
~
(
formatted
(
:field
lat
))
[
'<
~
(
formatted
(
:max
lat
))]}
{
~
(
formatted
(
:field
lat
))
[
'>
~
(
formatted
(
:min
lat
))]}
{
~
(
formatted
(
:field
lon
))
[
'<
~
(
formatted
(
:max
lon
))]}
{
~
(
formatted
(
:field
lon
))
[
'>
~
(
formatted
(
:min
lon
))]}))
;;
INSIDE
filter subclause
(
let
[{
:keys
[
lat
lon
]}
filter
]
(
list
'and
{(
formatted
(
:field
lat
))
[
'<
(
formatted
(
:max
lat
))]}
{(
formatted
(
:field
lat
))
[
'>
(
formatted
(
:min
lat
))]}
{(
formatted
(
:field
lon
))
[
'<
(
formatted
(
:max
lon
))]}
{(
formatted
(
:field
lon
))
[
'>
(
formatted
(
:min
lon
))]}))
;; all other filter subclauses
(
let
[
field
(
formatted
(
:field
filter
))
...
...
@@ -174,17 +181,10 @@
(
defmethod
apply-form
:order-by
[[
_
subclauses
]]
(
vec
(
for
[{
:keys
[
field
direction
]}
subclauses
]
(
do
(
println
"FIELD:"
field
)
`
(
order
~
(
if
(
=
(
:source
field
)
:aggregation
)
;; order by an aggregate Field
(
let
[{
:keys
[
aggregation-type
]}
(
:aggregation
(
:query
qp/*query*
))]
`
(
raw
~
(
format
"\"%s\""
(
name
aggregation-type
))))
;; order by a normal Field
(
formatted
field
))
~
(
case
direction
:ascending
:ASC
:descending
:DESC
))))))
`
(
order
~
(
formatted
field
)
~
(
case
direction
:ascending
:ASC
:descending
:DESC
)))))
;; TODO - page can be preprocessed away -- converted to a :limit clause and an :offset clause
;; implement this at some point.
...
...
This diff is collapsed.
Click to expand it.
test/metabase/driver/query_processor_test.clj
+
0
−
16
View file @
fca0c77a
...
...
@@ -532,22 +532,6 @@
[(
id
:checkins
:venue_id
)
"ascending"
]]})
;; ## EMPTY QUERY
;; Just don't barf
(
datasets/expect-with-all-datasets
{
:status
:completed
:row_count
0
:data
{
:rows
[]
,
:columns
[]
,
:cols
[]}}
(
driver/process-query
{
:type
:query
:database
(
db-id
)
:native
{}
:query
{
:source_table
0
:filter
[
nil
nil
]
:aggregation
[
"rows"
]
:breakout
[
nil
]
:limit
nil
}}))
;; # POST PROCESSING TESTS
;; ## LIMIT-MAX-RESULT-ROWS
...
...
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