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
605eaf64
Unverified
Commit
605eaf64
authored
1 year ago
by
Braden Shepherdson
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
[MLv2] Make `query=` treat missing `:base-type` as matching (#37727)
Fixes #37659
parent
17813df1
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/lib/js.cljs
+36
-1
36 additions, 1 deletion
src/metabase/lib/js.cljs
test/metabase/lib/js_test.cljs
+30
-0
30 additions, 0 deletions
test/metabase/lib/js_test.cljs
with
66 additions
and
1 deletion
src/metabase/lib/js.cljs
+
36
−
1
View file @
605eaf64
...
...
@@ -340,6 +340,41 @@
;; match up. Therefore de-dupe with `frequencies` rather than simply `set`.
(
assoc
inner-query
:fields
(
frequencies
fields
)))))))
(
defn-
compare-legacy-field-refs
[[
key1
id1
opts1
]
[
key2
id2
opts2
]]
;; A mismatch of `:base-type` or `:effective-type` when both x and y have values for it is a failure.
;; If either ref does not have the `:base-type` or `:effective-type` set, that key is ignored.
(
letfn
[(
clean-opts
[
o1
o2
]
(
not-empty
(
cond->
o1
(
not
(
:base-type
o2
))
(
dissoc
:base-type
)
(
not
(
:effective-type
o2
))
(
dissoc
:effective-type
))))]
(
=
[
key1
id1
(
clean-opts
opts1
opts2
)]
[
key2
id2
(
clean-opts
opts2
opts1
)])))
(
defn-
query=*
[
x
y
]
(
cond
(
and
(
vector?
x
)
(
vector?
y
)
(
=
(
first
x
)
(
first
y
)
:field
))
(
compare-legacy-field-refs
x
y
)
;; Otherwise this is a duplicate of clojure.core/=.
(
and
(
map?
x
)
(
map?
y
))
(
and
(
=
(
set
(
keys
x
))
(
set
(
keys
y
)))
(
every?
(
fn
[[
k
v
]]
(
query=*
v
(
get
y
k
)))
x
))
(
and
(
sequential?
x
)
(
sequential?
y
))
(
and
(
=
(
count
x
)
(
count
y
))
(
every?
true?
(
map
query=*
x
y
)))
;; Either mismatched map/sequence/nil/etc., or primitives like strings.
;; Either way, = does the right thing.
:else
(
=
x
y
)))
(
defn
^
:export
query=
"Returns whether the provided queries should be considered equal.
...
...
@@ -354,7 +389,7 @@
([
query1
query2
field-ids
]
(
let
[
n1
(
prep-query-for-equals
query1
field-ids
)
n2
(
prep-query-for-equals
query2
field-ids
)]
(
=
n1
n2
))))
(
query=*
n1
n2
))))
(
defn
^
:export
group-columns
"Given a group of columns returned by a function like [[metabase.lib.js/orderable-columns]], group the columns
...
...
This diff is collapsed.
Click to expand it.
test/metabase/lib/js_test.cljs
+
30
−
0
View file @
605eaf64
...
...
@@ -72,6 +72,36 @@
(
is
(
not=
(
js->clj
join
)
(
js->clj
join-class
)))
(
is
(
lib.js/query=
basic-query
classy-query
)))))
(
defn-
query-with-field-opts
[
opts
]
#
js
{
"type"
"query"
"query"
#
js
{
"source-table"
1
"filter"
#
js
[
"="
#
js
[
"field"
12
opts
]
7
]}})
(
deftest
^
:parallel
query=-field-types-test
(
testing
"equal field types are equal"
(
is
(
lib.js/query=
(
query-with-field-opts
#
js
{
"base-type"
"type/Text"
})
(
query-with-field-opts
#
js
{
"base-type"
"type/Text"
})))
(
is
(
lib.js/query=
(
query-with-field-opts
#
js
{
"effective-type"
"type/Float"
})
(
query-with-field-opts
#
js
{
"effective-type"
"type/Float"
}))))
(
testing
"mismatched field types are not equal"
(
is
(
not
(
lib.js/query=
(
query-with-field-opts
#
js
{
"base-type"
"type/Text"
})
(
query-with-field-opts
#
js
{
"base-type"
"type/Float"
}))))
(
is
(
not
(
lib.js/query=
(
query-with-field-opts
#
js
{
"effective-type"
"type/Text"
})
(
query-with-field-opts
#
js
{
"effective-type"
"type/Float"
})))))
(
testing
"missing field types are equal"
(
is
(
lib.js/query=
(
query-with-field-opts
#
js
{
"base-type"
"type/Text"
})
(
query-with-field-opts
#
js
{})))
(
is
(
lib.js/query=
(
query-with-field-opts
#
js
{})
(
query-with-field-opts
#
js
{
"base-type"
"type/Text"
})))
(
is
(
lib.js/query=
(
query-with-field-opts
#
js
{
"effective-type"
"type/Text"
})
(
query-with-field-opts
nil
)))
(
is
(
lib.js/query=
(
query-with-field-opts
#
js
{})
(
query-with-field-opts
#
js
{
"effective-type"
"type/Text"
})))
(
is
(
lib.js/query=
(
query-with-field-opts
#
js
{})
(
query-with-field-opts
nil
)))))
(
deftest
^
:parallel
available-join-strategies-test
(
testing
"available-join-strategies returns an array of opaque strategy objects (#32089)"
(
let
[
strategies
(
lib.js/available-join-strategies
lib.tu/query-with-join
-1
)]
...
...
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