Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QP, lib] Allow multiple arguments to :contains, :starts-with, etc. #41958

Merged
merged 1 commit into from May 1, 2024

Conversation

bshepherdson
Copy link
Contributor

These string matching clauses only allowed two arguments previously.
Typically [:contains field x] to match a field against a literal.

This adds similar desugaring for :contains, :does-not-contain,
:starts-with and :ends-with that is currently done for
multi-argument := and :!=:

[:contains field x y z] ;; ->
[:or [:contains field x] [:contains field y] [:contains field z]]

[:does-not-contain field x y z] ;; ->
[:and [:does-not-contain field x]
      [:does-not-contain field y]
      [:does-not-contain field z]]

Part of epic #41956.

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @bshepherdson and the rest of your teammates on Graphite Graphite

@metabase-bot metabase-bot bot added the .Team/QueryProcessor :hammer_and_wrench: label Apr 29, 2024
Copy link

replay-io bot commented Apr 29, 2024

Status Complete ↗︎
Commit fba27e4
Results
⚠️ 6 Flaky
2443 Passed

@bshepherdson bshepherdson added the no-backport Do not backport this PR to any branch label Apr 29, 2024
Copy link
Contributor

@metamben metamben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I expected new test cases for the now-muilt-arg functions other than :does-not-contain too.

@ranquild
Copy link
Contributor

ranquild commented Apr 30, 2024

@bshepherdson when we attempt to create a contains filter with 2 values it fails

#error {:message "Error calculating display info for contains: Error calculating metadata for :contains: Error calculating column name for [:contains {:case-sensitive false, :lib/uuid \"c51e0fc5-7ef8-4ec1-847b-219940206a15\"} [:field {:base-type :type/Text, :lib/uuid \"303f37e1-187d-4b90-91cf-d215b750e948\"} 70] \"a\" \"b\"]: Cannot read properties of null (reading 'replace')", :data {:query {:lib/type :mbql/query, :stages [{:lib/type :mbql.stage/mbql, :source-table 8, :filters [[:contains {:case-sensitive false, :lib/uuid "c51e0fc5-7ef8-4ec1-847b-219940206a15"} [:field {:base-type :type/Text, :lib/uuid "303f37e1-187d-4b90-91cf-d215b750e948"} 70] "a" "b"]]}], :database 1, :lib/metadata #object[metabase.lib.js.metadata.t_metabase$lib$js$metadata70135]}, :stage-number -1, :x [:contains {:case-sensitive false, :lib/uuid "c51e0fc5-7ef8-4ec1-847b-219940206a15"} [:field {:base-type :type/Text, :lib/uuid "303f37e1-187d-4b90-91cf-d215b750e948"} 70] "a" "b"]}, :cause #error {:message "Error calculating metadata for :contains: Error calculating column name for [:contains {:case-sensitive false, :lib/uuid \"c51e0fc5-7ef8-4ec1-847b-219940206a15\"} [:field {:base-type :type/Text, :lib/uuid \"303f37e1-187d-4b90-91cf-d215b750e948\"} 70] \"a\" \"b\"]: Cannot read properties of null (reading 'replace')", :data {:query {:lib/type :mbql/query, :stages [{:lib/type :mbql.stage/mbql, :source-table 8, :filters [[:contains {:case-sensitive false, :lib/uuid "c51e0fc5-7ef8-4ec1-847b-219940206a15"} [:field {:base-type :type/Text, :lib/uuid "303f37e1-187d-4b90-91cf-d215b750e948"} 70] "a" "b"]]}], :database 1, :lib/metadata #object[metabase.lib.js.metadata.t_metabase$lib$js$metadata70135]}, :stage-number -1, :x [:contains {:case-sensitive false, :lib/uuid "c51e0fc5-7ef8-4ec1-847b-219940206a15"} [:field {:base-type :type/Text, :lib/uuid "303f37e1-187d-4b90-91cf-d215b750e948"} 70] "a" "b"]}, :cause #error {:message "Error calculating column name for [:contains {:case-sensitive false, :lib/uuid \"c51e0fc5-7ef8-4ec1-847b-219940206a15\"} [:field {:base-type :type/Text, :lib/uuid \"303f37e1-187d-4b90-91cf-d215b750e948\"} 70] \"a\" \"b\"]: Cannot read properties of null (reading 'replace')", :data {:x [:contains {:case-sensitive false, :lib/uuid "c51e0fc5-7ef8-4ec1-847b-219940206a15"} [:field {:base-type :type/Text, :lib/uuid "303f37e1-187d-4b90-91cf-d215b750e948"} 70] "a" "b"], :query {:lib/type :mbql/query, :stages [{:lib/type :mbql.stage/mbql, :source-table 8, :filters [[:contains {:case-sensitive false, :lib/uuid "c51e0fc5-7ef8-4ec1-847b-219940206a15"} [:field {:base-type :type/Text, :lib/uuid "303f37e1-187d-4b90-91cf-d215b750e948"} 70] "a" "b"]]}], :database 1, :lib/metadata #object[metabase.lib.js.metadata.t_metabase$lib$js$metadata70135]}, :stage-number -1}, :cause #object[TypeError TypeError: Cannot read properties of null (reading 'replace')]}}}

@bshepherdson
Copy link
Contributor Author

@ranquild I'm reworking this PR a bit internally based on an out-of-band review from Cam. I'll make sure it works at the lib level before submitting it.

These string matching clauses only allowed two arguments previously.
Typically `[:contains field x]` to match a field against a literal.

This adds similar desugaring for `:contains`, `:does-not-contain`,
`:starts-with` and `:ends-with` that is currently done for
multi-argument `:=` and `:!=`:

```clojure
[:contains field x y z] ;; ->
[:or [:contains field x] [:contains field y] [:contains field z]]

[:does-not-contain field x y z] ;; ->
[:and [:does-not-contain field x]
      [:does-not-contain field y]
      [:does-not-contain field z]]
```
@bshepherdson bshepherdson force-pushed the qp-multi-argument-contains-et-al branch from f17148b to fba27e4 Compare May 1, 2024 12:12
@bshepherdson
Copy link
Contributor Author

@ranquild @nemanjaglumac This should be working from the JS side now.
2024-05-01-081838_1498x846_scrot

@bshepherdson bshepherdson enabled auto-merge (squash) May 1, 2024 12:22
@bshepherdson bshepherdson merged commit d142da9 into master May 1, 2024
110 checks passed
@bshepherdson bshepherdson deleted the qp-multi-argument-contains-et-al branch May 1, 2024 12:53
Copy link

github-actions bot commented May 1, 2024

@bshepherdson Did you forget to add a milestone to the issue for this PR? When and where should I add a milestone?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-backport Do not backport this PR to any branch .Team/QueryProcessor :hammer_and_wrench:
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants