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
ff37cea5
Commit
ff37cea5
authored
9 years ago
by
Cameron T Saul
Browse files
Options
Downloads
Patches
Plain Diff
New aggregate-col fn to simpify QP tests a bit
parent
9c573cb7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/metabase/driver/query_processor_test.clj
+70
-52
70 additions, 52 deletions
test/metabase/driver/query_processor_test.clj
test/metabase/test/data/datasets.clj
+9
-3
9 additions, 3 deletions
test/metabase/test/data/datasets.clj
with
79 additions
and
55 deletions
test/metabase/driver/query_processor_test.clj
+
70
−
52
View file @
ff37cea5
...
...
@@ -38,6 +38,9 @@
(
defn
id-field-type
[]
(
datasets/id-field-type
*dataset*
))
(
defn
timestamp-field-type
[]
(
datasets/timestamp-field-type
*dataset*
))
;; ## Dataset-Independent QP Tests
...
...
@@ -87,7 +90,7 @@
[]
(
->columns
"id"
"category_id"
"price"
"longitude"
"latitude"
"name"
))
(
defn
venue-col
(
defn
venue
s
-col
"Return column information for the `venues` column named by keyword COL."
[
col
]
(
case
col
...
...
@@ -139,7 +142,7 @@
(
defn
venues-cols
"`cols` information for all the columns in `venues`."
[]
(
mapv
venue-col
[
:id
:category_id
:price
:longitude
:latitude
:name
]))
(
mapv
venue
s
-col
[
:id
:category_id
:price
:longitude
:latitude
:name
]))
;; #### categories
(
defn
categories-col
...
...
@@ -204,25 +207,60 @@
:id
(
id
:users
:name
)}
:last_login
{
:extra_info
{}
:special_type
:category
:base_type
:DateTimeField
:base_type
(
timestamp-field-type
)
:description
nil
:name
(
format-name
"last_login"
)
:table_id
(
id
:users
)
:id
(
id
:users
:last_login
)}))
;;; #### aggregate columns
(
defn
aggregate-col
"Return the column information we'd expect for an aggregate column. For all columns besides `:count`, you'll need to pass the `Field` in question as well.
(aggregate-col :count)
(aggregate-col :avg (venues-col :id))"
{
:arglists
'
([
ag-col-kw
]
[
ag-col-kw
field
])}
([
ag-col-kw
]
(
case
ag-col-kw
:count
{
:base_type
:IntegerField
:special_type
:number
:name
"count"
:id
nil
:table_id
nil
:description
nil
}))
([
ag-col-kw
{
:keys
[
base_type
special_type
]}]
{
:pre
[
base_type
special_type
]}
(
case
ag-col-kw
:avg
{
:base_type
base_type
:special_type
special_type
:name
"avg"
:id
nil
:table_id
nil
:description
nil
}
:stddev
{
:base_type
base_type
:special_type
special_type
:name
"stddev"
:id
nil
:table_id
nil
:description
nil
}
:sum
{
:base_type
base_type
:special_type
special_type
:name
"sum"
:id
nil
:table_id
nil
:description
nil
})))
;; # THE TESTS THEMSELVES (!)
;; ### "COUNT" AGGREGATION
(
qp-expect-with-all-datasets
{
:rows
[[
100
]]
:columns
[
"count"
]
:cols
[{
:base_type
:IntegerField
:special_type
:number
:name
"count"
:id
nil
:table_id
nil
:description
nil
}]}
:cols
[(
aggregate-col
:count
)]}
{
:source_table
(
id
:venues
)
:filter
[
nil
nil
]
:aggregation
[
"count"
]
...
...
@@ -233,12 +271,7 @@
(
qp-expect-with-all-datasets
{
:rows
[[
203
]]
:columns
[
"sum"
]
:cols
[{
:base_type
:IntegerField
:special_type
:category
:name
"sum"
:id
nil
:table_id
nil
:description
nil
}]}
:cols
[(
aggregate-col
:sum
(
venues-col
:price
))]}
{
:source_table
(
id
:venues
)
:filter
[
nil
nil
]
:aggregation
[
"sum"
(
id
:venues
:price
)]
...
...
@@ -250,12 +283,7 @@
(
qp-expect-with-all-datasets
{
:rows
[[
35.50589199999998
]]
:columns
[
"avg"
]
:cols
[{
:base_type
:FloatField
:special_type
:latitude
:name
"avg"
:id
nil
:table_id
nil
:description
nil
}]}
:cols
[(
aggregate-col
:avg
(
venues-col
:latitude
))]}
{
:source_table
(
id
:venues
)
:filter
[
nil
nil
]
:aggregation
[
"avg"
(
id
:venues
:latitude
)]
...
...
@@ -267,12 +295,7 @@
(
qp-expect-with-all-datasets
{
:rows
[[
15
]]
:columns
[
"count"
]
:cols
[{
:base_type
:IntegerField
:special_type
:number
:name
"count"
:id
nil
:table_id
nil
:description
nil
}]}
:cols
[(
aggregate-col
:count
)]}
{
:source_table
(
id
:checkins
)
:filter
[
nil
nil
]
:aggregation
[
"distinct"
(
id
:checkins
:user_id
)]
...
...
@@ -408,12 +431,7 @@
(
qp-expect-with-all-datasets
{
:rows
[[
29
]]
:columns
[
"count"
]
:cols
[{
:base_type
:IntegerField
:special_type
:number
:name
"count"
:id
nil
:table_id
nil
:description
nil
}]}
:cols
[(
aggregate-col
:count
)]}
{
:source_table
(
id
:checkins
)
:filter
[
"AND"
[
"BETWEEN"
(
id
:checkins
:date
)
"2015-04-01"
"2015-05-01"
]]
:aggregation
[
"count"
]})
...
...
@@ -470,8 +488,8 @@
[
"Krua Siri"
9
]
[
"Fred 62"
10
]]
,
:columns
(
->columns
"name"
"id"
)
:cols
[(
venue-col
:name
)
(
venue-col
:id
)]}
:cols
[(
venue
s
-col
:name
)
(
venue
s
-col
:id
)]}
{
:source_table
(
id
:venues
)
:filter
[
nil
nil
]
:aggregation
[
"rows"
]
...
...
@@ -489,7 +507,7 @@
:columns
[(
format-name
"user_id"
)
"count"
]
:cols
[(
checkins-col
:user_id
)
{
:base_type
:IntegerField,
:special_type
:number,
:name
"count"
,
:id
nil,
:table_id
nil,
:description
nil
}
]}
(
aggregate-col
:count
)
]}
{
:source_table
(
id
:checkins
)
:filter
[
nil
nil
]
:aggregation
[
"count"
]
...
...
@@ -506,7 +524,7 @@
"count"
]
:cols
[(
checkins-col
:user_id
)
(
checkins-col
:venue_id
)
{
:base_type
:IntegerField,
:special_type
:number,
:name
"count"
,
:id
nil,
:table_id
nil,
:description
nil
}
]}
(
aggregate-col
:count
)
]}
{
:source_table
(
id
:checkins
)
:limit
10
:aggregation
[
"count"
]
...
...
@@ -522,7 +540,7 @@
"count"
]
:cols
[(
checkins-col
:user_id
)
(
checkins-col
:venue_id
)
{
:base_type
:IntegerField,
:special_type
:number,
:name
"count"
,
:id
nil,
:table_id
nil,
:description
nil
}
]}
(
aggregate-col
:count
)
]}
{
:source_table
(
id
:checkins
)
:limit
10
:aggregation
[
"count"
]
...
...
@@ -572,7 +590,7 @@
(
qp-expect-with-all-datasets
{
:rows
[[(
->sum-type
120
)]]
:columns
[
"sum"
]
:cols
[
{
:base_type
(
id-field-type
)
,
:special_type
:id,
:name
"sum"
,
:id
nil,
:table_id
nil,
:description
nil
}
]}
:cols
[
(
aggregate-col
:sum
(
users-col
:id
))
]}
{
:source_table
(
id
:users
)
:aggregation
[
"cum_sum"
(
id
:users
:id
)]})
...
...
@@ -607,7 +625,7 @@
:columns
[(
format-name
"name"
)
"sum"
]
:cols
[(
users-col
:name
)
{
:base_type
(
id-field-type
)
,
:special_type
:id,
:name
"sum"
,
:id
nil,
:table_id
nil,
:description
nil
}
]}
(
aggregate-col
:sum
(
users-col
:id
))
]}
{
:source_table
(
id
:users
)
:breakout
[(
id
:users
:name
)]
:aggregation
[
"cum_sum"
(
id
:users
:id
)]})
...
...
@@ -617,8 +635,8 @@
(
qp-expect-with-all-datasets
{
:columns
[(
format-name
"price"
)
"sum"
]
:cols
[(
venue-col
:price
)
{
:base_type
(
id-field-type
)
,
:special_type
:id,
:name
"sum"
,
:id
nil,
:table_id
nil,
:description
nil
}
]
:cols
[(
venue
s
-col
:price
)
(
aggregate-col
:sum
(
venues-col
:id
))
]
:rows
[[
1
(
->sum-type
1211
)]
[
2
(
->sum-type
4066
)]
[
3
(
->sum-type
4681
)]
...
...
@@ -638,8 +656,8 @@
[
3
13
]
[
1
22
]
[
2
59
]]
:cols
[(
venue-col
:price
)
{
:base_type
:IntegerField,
:special_type
:number,
:description
nil,
:table_id
nil,
:name
"count"
,
:id
nil
}
]}
:cols
[(
venue
s
-col
:price
)
(
aggregate-col
:count
)
]}
{
:source_table
(
id
:venues
)
:aggregation
[
"count"
]
:breakout
[(
id
:venues
:price
)]
...
...
@@ -654,8 +672,8 @@
[
1
(
->sum-type
1211
)]
[
3
(
->sum-type
615
)]
[
4
(
->sum-type
369
)]]
:cols
[(
venue-col
:price
)
{
:base_type
(
id-field-type
)
,
:special_type
:id,
:name
"sum"
,
:id
nil,
:table_id
nil,
:description
nil
}
]}
:cols
[(
venue
s
-col
:price
)
(
aggregate-col
:sum
(
venues-col
:id
))
]}
{
:source_table
(
id
:venues
)
:aggregation
[
"sum"
(
id
:venues
:id
)]
:breakout
[(
id
:venues
:price
)]
...
...
@@ -670,8 +688,8 @@
[
3
13
]
[
1
22
]
[
2
59
]]
:cols
[(
venue-col
:price
)
{
:base_type
:IntegerField,
:special_type
:number,
:name
"count"
,
:id
nil,
:table_id
nil,
:description
nil
}
]}
:cols
[(
venue
s
-col
:price
)
(
aggregate-col
:count
)
]}
{
:source_table
(
id
:venues
)
:aggregation
[
"distinct"
(
id
:venues
:id
)]
:breakout
[(
id
:venues
:price
)]
...
...
@@ -686,8 +704,8 @@
[
2
28
]
[
1
32
]
[
4
53
]]
:cols
[(
venue-col
:price
)
{
:base_type
:IntegerField,
:special_type
:fk,
:name
"avg"
,
:id
nil,
:table_id
nil,
:description
nil
}
]}
:cols
[(
venue
s
-col
:price
)
(
aggregate-col
:avg
(
venues-col
:category_id
))
]}
{
:source_table
(
id
:venues
)
:aggregation
[
"avg"
(
id
:venues
:category_id
)]
:breakout
[(
id
:venues
:price
)]
...
...
@@ -701,8 +719,8 @@
[
1
24.112111881665186
]
[
2
21.418692164795292
]
[
4
14.788509052639485
]]
:cols
[(
venue-col
:price
)
{
:base_type
:IntegerField,
:special_type
:fk,
:name
"stddev"
,
:id
nil,
:table_id
nil,
:description
nil
}
]}
:cols
[(
venue
s
-col
:price
)
(
aggregate-col
:stddev
(
venues-col
:category_id
))
]}
{
:source_table
(
id
:venues
)
:aggregation
[
"stddev"
(
id
:venues
:category_id
)]
:breakout
[(
id
:venues
:price
)]
...
...
This diff is collapsed.
Click to expand it.
test/metabase/test/data/datasets.clj
+
9
−
3
View file @
ff37cea5
...
...
@@ -28,7 +28,9 @@
"Transform a lowercase string `Table` or `Field` name in a way appropriate for this dataset
(e.g., `h2` would want to upcase these names; `mongo` would want to use `\"_id\"` in place of `\"id\"`."
)
(
id-field-type
[
this
]
"Return the `base_type` of the `id` `Field` (e.g. `:IntegerField` or `:BigIntegerField`)."
))
"Return the `base_type` of the `id` `Field` (e.g. `:IntegerField` or `:BigIntegerField`)."
)
(
timestamp-field-type
[
this
]
"Return the `base_type` of a `TIMESTAMP` `Field` like `users.last_login`."
))
;; # Implementations
...
...
@@ -56,7 +58,9 @@
(
if
(
=
table-or-field-name
"id"
)
"_id"
table-or-field-name
))
(
id-field-type
[
_
]
:IntegerField
))
:IntegerField
)
(
timestamp-field-type
[
_
]
:DateField
))
;; ## Generic SQL
...
...
@@ -79,7 +83,9 @@
(
format-name
[
_
table-or-field-name
]
(
clojure.string/upper-case
table-or-field-name
))
(
id-field-type
[
_
]
:BigIntegerField
))
:BigIntegerField
)
(
timestamp-field-type
[
_
]
:DateTimeField
))
;; # Concrete Instances
...
...
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