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
f8bd3d6f
Unverified
Commit
f8bd3d6f
authored
7 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
Just test SQL query generated with params for H2 [ci drivers]
parent
0928af40
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
test/metabase/query_processor/middleware/parameters/mbql_test.clj
+13
-30
13 additions, 30 deletions
...abase/query_processor/middleware/parameters/mbql_test.clj
test/metabase/test/data/generic_sql.clj
+1
-0
1 addition, 0 deletions
test/metabase/test/data/generic_sql.clj
with
14 additions
and
30 deletions
test/metabase/query_processor/middleware/parameters/mbql_test.clj
+
13
−
30
View file @
f8bd3d6f
(
ns
metabase.query-processor.middleware.parameters.mbql-test
"Tests for *MBQL* parameter substitution."
(
:require
[
expectations
:refer
:all
]
[
honeysql.core
:as
hsql
]
[
metabase
[
query-processor
:as
qp
]
[
query-processor-test
:refer
[
first-row
format-rows-by
non-timeseries-engines
rows
]]
[
util
:as
u
]]
[
metabase.driver.generic-sql
:as
sql
]
[
metabase.models
[
field
:refer
[
Field
]]
[
table
:refer
[
Table
]]]
...
...
@@ -207,29 +209,13 @@
(
rows
(
qp/process-query
outer-query
)))))
;; now let's make sure the correct query is actually being generated for the same thing above...
;;
;; TODO - the util function below is similar to a few other ones that are used elsewhere in the tests. It would be
;; nice to unifiy those at some point or possibly move them into a shared utility namespace. Something to consider!
(
defn-
mbql-param-quoted-and-qualified-name
"Generate a quoted and qualified identifier for a Table or Field for the current driver that will be used for MBQL
param subsitution below. e.g.
;; with SQLServer
(mbql-param-quoted-and-qualified-name :venues) ;-> :dbo.venues
(mbql-param-quoted-and-qualified-name :venues :price) ;-> :dbo.venues.price"
([
table-kw
]
(
let
[
table
(
Table
(
data/id
table-kw
))]
(
hx/qualify-and-escape-dots
(
:schema
table
)
(
:name
table
))))
([
table-kw
field-kw
]
(
let
[
table
(
Table
(
data/id
table-kw
))
field
(
Field
(
data/id
table-kw
field-kw
))]
(
hx/qualify-and-escape-dots
(
:schema
table
)
(
:name
table
)
(
:name
field
)))))
(
datasets/expect-with-engines
params-test-engines
{
:query
(
format
"SELECT count(*) AS \"count\" FROM %s WHERE (%s = 3 OR %s = 4)"
(
mbql-param-quoted-and-qualified-name
:venues
)
(
mbql-param-quoted-and-qualified-name
:venues
:price
)
(
mbql-param-quoted-and-qualified-name
:venues
:price
))
;; (NOTE: We're only testing this with H2 because the SQL generated is simply too different between various SQL drivers.
;; we know the features are still working correctly because we're actually checking that we get the right result from
;; running the query above these tests are more of a sanity check to make sure the SQL generated is sane.)
(
datasets/expect-with-engine
:h2
{
:query
(
str
"SELECT count(*) AS \"count\" "
"FROM \"PUBLIC\".\"VENUES\" "
"WHERE (\"PUBLIC\".\"VENUES\".\"PRICE\" = 3 OR \"PUBLIC\".\"VENUES\".\"PRICE\" = 4)"
)
:params
nil
}
(
let
[
inner-query
(
data/query
venues
(
ql/aggregation
(
ql/count
)))
...
...
@@ -243,13 +229,10 @@
;; try it with date params as well. Even though there's no way to do this in the frontend AFAIK there's no reason we
;; can't handle it on the backend
(
datasets/expect-with-engines
params-test-engines
{
:query
(
format
(
str
"SELECT count(*) AS \"count\" FROM %s "
"WHERE (CAST(%s AS date) BETWEEN CAST(? AS date) AND CAST(? AS date) "
"OR CAST(%s date) BETWEEN CAST(? AS date) AND CAST(? AS date))"
)
(
mbql-param-quoted-and-qualified-name
:checkins
)
(
mbql-param-quoted-and-qualified-name
:checkins
:date
)
(
mbql-param-quoted-and-qualified-name
:checkins
:date
))
(
datasets/expect-with-engine
:h2
{
:query
(
str
"SELECT count(*) AS \"count\" FROM \"PUBLIC\".\"CHECKINS\" "
"WHERE (CAST(\"PUBLIC\".\"CHECKINS\".\"DATE\" AS date) BETWEEN CAST(? AS date) AND CAST(? AS date) "
"OR CAST(\"PUBLIC\".\"CHECKINS\".\"DATE\" AS date) BETWEEN CAST(? AS date) AND CAST(? AS date))"
)
:params
[(
u/->Timestamp
#
inst
"2014-06-01"
)
(
u/->Timestamp
#
inst
"2014-06-30"
)
(
u/->Timestamp
#
inst
"2015-06-01"
)
...
...
This diff is collapsed.
Click to expand it.
test/metabase/test/data/generic_sql.clj
+
1
−
0
View file @
f8bd3d6f
...
...
@@ -66,6 +66,7 @@
By default, this qualifies field names with their table name, but otherwise does no other specific
qualification."
)
;; TODO - why can't we just use `honeysql.core/format` with the `:quoting` options set to the driver's `quote-style`?
(
quote-name
^
String
[
this,
^
String
nm
]
"*Optional*. Quote a name. Defaults to using double quotes."
)
...
...
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