add any_match higher-order function#21903
Conversation
|
|
||
| # predicate returns null for some elements but true for others -> true | ||
| query B | ||
| SELECT array_any_match([1, NULL, 10], x -> x > 5); |
There was a problem hiding this comment.
would be nice to add more tests with nulls
select a, exists(array(1, 2, 3), x-> case when a = 2 then x > 1 else null end)
select exists(array(1, 2, 3), x-> null)
There was a problem hiding this comment.
done, we cannot yet add a test for
select a, exists(array(1, 2, 3), x-> case when a = 2 then x > 1 else null end)
because column capture is not yet supported
7ea1120 to
392b52b
Compare
|
👋 @LiaCastaneda PR #21895 (currently open) adds
|
|
From @benbellick 's suggestion I verified we are following the substrait semantics/ conventions: https://github.com/substrait-io/substrait/blob/19716584708f98b06eb3f0d73a1f62e15bf6b169/tests/cases/list/any_match.test |
comphead
left a comment
There was a problem hiding this comment.
THanks @LiaCastaneda the PR looks good to me overall, only nit:
lets rename higher_order.slt into array_any_match.slt
|
I splitted the tests for each function into different sqllogic test files in |
comphead
left a comment
There was a problem hiding this comment.
Thanks @LiaCastaneda its LGTM
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes apache#123` indicates that this PR will close issue apache#123. --> - Closes #. ## Rationale for this change `array_any_match` is a commonly supported higher-order function in systems like Spark (`exists`), Trino (`any_match`) among other engines. It seems like a natural first addition alongside `array_transform` and worth upstreaming I think. ## What changes are included in this PR? Adds `array_any_match(array, predicate)` as a new higher-order function (with aliases `any_match` and `list_any_match`). It returns: `true` if any element satisfies the predicate `false` if no element does (including empty arrays) `null` if the predicate returns null for some elements and false for all others ## Are these changes tested? Yes I added unit tests and sqllogic tests ## Are there any user-facing changes? Yes -- new SQL functions array_any_match, any_match, and list_any_match are available. --------- Co-authored-by: Dmitrii Blaginin <dmitrii@blaginin.me>
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes #. ## Rationale for this change `array_any_match` is a commonly supported higher-order function in systems like Spark (`exists`), Trino (`any_match`) among other engines. It seems like a natural first addition alongside `array_transform` and worth upstreaming I think. ## What changes are included in this PR? Adds `array_any_match(array, predicate)` as a new higher-order function (with aliases `any_match` and `list_any_match`). It returns: `true` if any element satisfies the predicate `false` if no element does (including empty arrays) `null` if the predicate returns null for some elements and false for all others ## Are these changes tested? Yes I added unit tests and sqllogic tests ## Are there any user-facing changes? Yes -- new SQL functions array_any_match, any_match, and list_any_match are available. --------- Co-authored-by: Dmitrii Blaginin <dmitrii@blaginin.me>
Which issue does this PR close?
Rationale for this change
array_any_matchis a commonly supported higher-order function in systems like Spark (exists), Trino (any_match) among other engines. It seems like a natural first addition alongsidearray_transformand worth upstreaming I think.What changes are included in this PR?
Adds
array_any_match(array, predicate)as a new higher-order function (with aliasesany_matchandlist_any_match). It returns:trueif any element satisfies the predicatefalseif no element does (including empty arrays)nullif the predicate returns null for some elements and false for all othersAre these changes tested?
Yes I added unit tests and sqllogic tests
Are there any user-facing changes?
Yes -- new SQL functions array_any_match, any_match, and list_any_match are available.