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
be231ec8
Unverified
Commit
be231ec8
authored
1 year ago
by
Braden Shepherdson
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
[MLv2] Add `display-info` for queries (#37675)
Fixes #36973.
parent
045a54da
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/metabase/lib/metadata.cljc
+2
-1
2 additions, 1 deletion
src/metabase/lib/metadata.cljc
src/metabase/lib/query.cljc
+11
-0
11 additions, 0 deletions
src/metabase/lib/query.cljc
test/metabase/lib/query_test.cljc
+38
-2
38 additions, 2 deletions
test/metabase/lib/query_test.cljc
with
51 additions
and
3 deletions
src/metabase/lib/metadata.cljc
+
2
−
1
View file @
be231ec8
...
...
@@ -220,7 +220,8 @@
If metadata for the `:source-table` or `:source-card` can be found, then the query is editable."
[
query
:-
::lib.schema/query
]
(
let
[{
:keys
[
source-table
source-card
]
:as
stage0
}
(
lib.util/query-stage
query
0
)]
(
boolean
(
and
(
database
query
)
(
boolean
(
and
(
when-let
[{
:keys
[
id
]}
(
database
query
)]
(
=
(
:database
query
)
id
))
(
or
(
and
source-table
(
table
query
source-table
))
(
and
source-card
(
card
query
source-card
))
(
=
(
:lib/type
stage0
)
:mbql.stage/native
))))))
This diff is collapsed.
Click to expand it.
src/metabase/lib/query.cljc
+
11
−
0
View file @
be231ec8
...
...
@@ -40,6 +40,17 @@
[
query
stage-number
x
style
]
(
lib.metadata.calculation/display-name
query
stage-number
(
lib.util/query-stage
x
stage-number
)
style
))
(
mu/defn
native?
:-
:boolean
"Given a query, return whether it is a native query."
[
query
:-
::lib.schema/query
]
(
let
[
stage
(
lib.util/query-stage
query
0
)]
(
=
(
:lib/type
stage
)
:mbql.stage/native
)))
(
defmethod
lib.metadata.calculation/display-info-method
:mbql/query
[
_query
_stage-number
query
]
{
:is-native
(
native?
query
)
:is-editable
(
lib.metadata/editable?
query
)})
(
mu/defn
stage-count
:-
::lib.schema.common/int-greater-than-or-equal-to-zero
"Returns the count of stages in query"
[
query
:-
::lib.schema/query
]
...
...
This diff is collapsed.
Click to expand it.
test/metabase/lib/query_test.cljc
+
38
−
2
View file @
be231ec8
(
ns
metabase.lib.query-test
(
:require
#
?
@
(
:cljs
([
metabase.test-runner.assert-exprs.approximately-equal
]))
[
clojure.test
:refer
[
deftest
is
testing
]]
[
clojure.test
:refer
[
are
deftest
is
testing
]]
[
clojure.walk
:as
walk
]
[
metabase.lib.convert
:as
lib.convert
]
[
metabase.lib.core
:as
lib
]
[
metabase.lib.query
:as
lib.query
]
[
metabase.lib.test-metadata
:as
meta
]
[
metabase.lib.test-util
:as
lib.tu
]))
[
metabase.lib.test-util
:as
lib.tu
]
[
metabase.lib.util
:as
lib.util
]
[
metabase.util.malli
:as
mu
]))
#
?
(
:cljs
(
comment
metabase.test-runner.assert-exprs.approximately-equal/keep-me
))
...
...
@@ -95,3 +98,36 @@
(
is
(
=
1
(
lib/stage-count
lib.tu/venues-query
)))
(
is
(
=
2
(
lib/stage-count
(
lib/append-stage
lib.tu/venues-query
))))
(
is
(
=
3
(
lib/stage-count
(
lib/append-stage
(
lib/append-stage
lib.tu/venues-query
))))))
(
deftest
^
:parallel
native?-test
(
testing
"MBQL queries are not native"
(
is
(
not
(
lib.query/native?
(
lib/query
meta/metadata-provider
(
meta/table-metadata
:orders
))))))
(
testing
"SQL queries are native"
(
is
(
lib.query/native?
(
lib/native-query
meta/metadata-provider
"SELECT * FROM Orders;"
)))))
(
deftest
^
:parallel
display-info-test
(
testing
"display-info"
(
testing
"on MBQL queries"
(
let
[
editable
(
lib/query
meta/metadata-provider
(
meta/table-metadata
:orders
))]
(
are
[
editable?
query
]
(
=
{
:is-native
false
:is-editable
editable?
}
(
mu/disable-enforcement
(
lib/display-info
query
-1
query
)))
true
editable
false
(
assoc
editable
:database
999999999
)
; database unknown - no permissions
false
(
assoc-in
editable
[
:stages
0
:source-table
]
999999999
)
; source-table not visible
false
(
lib.util/update-query-stage
editable
0
#
(
->
%
; source-card not visible
(
assoc
:source-card
999999999
)
(
dissoc
:source-table
))))))
(
testing
"on native queries"
(
let
[
editable
(
lib/native-query
meta/metadata-provider
"SELECT * FROM Venues;"
)
bad-db
(
assoc
editable
:database
999999999
)]
(
is
(
=
{
:is-native
true
:is-editable
true
}
(
lib/display-info
editable
-1
editable
)))
(
is
(
=
{
:is-native
true
:is-editable
false
}
(
lib/display-info
bad-db
-1
bad-db
)))))))
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