Repository navigation
Support IS DISTINCT FROM / IS NOT DISTINCT FROM in the SOME/ALL array quantifier - #107454
Merged
Merged
Conversation
…L` array quantifier Follow-up to #105129, which added the PostgreSQL-style `expr OP SOME(array)` / `expr OP ALL(array)` array quantifier but only for operators tagged `OperatorType::Comparison` (`=`, `==`, `!=`, `<>`, `<=>`, `<`, `<=`, `>`, `>=`). The keyword predicates `IS DISTINCT FROM` and `IS NOT DISTINCT FROM` carry the default `OperatorType::None`, so they were never routed through the rewrite, even though they are comparison predicates - `1 IS DISTINCT FROM ALL([2, 3])` was not recognised as the array quantifier. Route `IS DISTINCT FROM` / `IS NOT DISTINCT FROM` through the `arrayExists` / `arrayAll` lambda form as well, by peeking at the pending operator's function name (new `Layer::previousOperator`) in addition to its `OperatorType`. The subquery -> `IN` / `NOT IN` path stays restricted to symbolic comparison operators, where it has meaning. The string-search predicates `LIKE`, `ILIKE`, `NOT LIKE`, `NOT ILIKE`, and `REGEXP` are deliberately excluded from the array form: their implementation (`MatchImpl`) does not support a constant haystack with a non-constant needle, so `'abc' LIKE SOME([...])` would throw `ILLEGAL_COLUMN`. The operator documentation now lists the exact supported operators and explains that these predicates must be written out with `arrayExists` / `arrayAll`. Addresses the review on #105129: #105129 (comment) Co-Authored-By: Claude Opus 4.8 <[email protected]>
Contributor
|
Workflow [PR], commit [a98503f] Summary: ✅
AI ReviewSummaryThis PR extends the Findings
Tests
Final VerdictStatus: Minimum required action: handle or explicitly document the |
… string-search predicates The `SOME` / `ALL` array-quantifier documentation listed `LIKE`, `ILIKE`, `REGEXP`, etc. as excluded from the array form and then advised users to "use `arrayExists` / `arrayAll` directly". For the string-search predicates that advice is wrong: the natural rewrite `arrayExists(x -> 'abc' LIKE x, ['a%', 'b%'])` puts the lambda variable in `MatchImpl`'s pattern (needle) position, which must be constant, so it throws `ILLEGAL_COLUMN` - the same unsupported shape the array form deliberately avoids. Explain that the string-search predicates cannot be emulated with `arrayExists` / `arrayAll` either, and point to working alternatives: an explicit disjunction of constant patterns, or a multi-pattern search function (`multiMatchAny` / `multiSearchAny`). Clarify that the `arrayExists` / `arrayAll` form is a drop-in replacement only for the genuine comparison operators. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…dicates The comment for the excluded string-search predicates (`LIKE`, `ILIKE`, `REGEXP`, ...) in `04241_any_all_on_arrays.sql` still advised writing such queries out "explicitly with `arrayExists` / `arrayAll`", which contradicts the preceding sentence in the same comment: the naive rewrite `arrayExists(x -> 'abc' LIKE x, ...)` puts the lambda variable in `MatchImpl`'s non-constant pattern position and throws `ILLEGAL_COLUMN`. Align the comment with the docs fix in `032d5b26d0d`: these predicates cannot be emulated with `arrayExists` / `arrayAll` either; to match one string against several patterns, use an explicit disjunction of constant patterns or a multi-pattern search function such as `multiMatchAny` / `multiSearchAny`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…rray quantifier The new `IS DISTINCT FROM` / `IS NOT DISTINCT FROM` coverage in `04241_any_all_on_arrays` only exercised non-`NULL` operands, so it proved that the parser accepts the keyword predicates but not the null-safe semantics that distinguish them from `!=` / `=`. Add minimal `NULL` cases for both predicates with `SOME` and `ALL`, chosen so an accidental rewrite to `notEquals` / `equals` would change the result (for example `NULL IS NOT DISTINCT FROM SOME([NULL, 1])` is `1`, while `equals` would fold to `0`; `1 IS DISTINCT FROM ALL([NULL])` is `1`, while `notEquals` would fold to `0`). Two equivalence assertions also pin the keyword form to the explicit `arrayExists` / `arrayAll` lambda form on `NULL` inputs. Addresses #107454 (comment) review from `clickhouse-gh`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
`MatchImpl` supports a constant haystack with a non-constant needle (since the merge of #100479 into `master`), so the earlier exclusion of `LIKE`, `ILIKE`, `NOT LIKE`, `NOT ILIKE`, and `REGEXP` from the `SOME` / `ALL` array quantifier no longer applies: `'abc' LIKE SOME(['a%', 'b%'])` rewrites to `arrayExists(x -> 'abc' LIKE x, ['a%', 'b%'])` and evaluates without throwing. Route these predicates through the same `arrayExists` / `arrayAll` lambda rewrite as the keyword comparison predicates, correct the now-false parser comment and the operator documentation, and replace the `UNKNOWN_FUNCTION` assertion in the test with positive coverage (`LIKE` / `ILIKE` / `NOT LIKE` / `NOT ILIKE` / `REGEXP` with `SOME` / `ALL`, including `NULL` patterns and equivalence to the explicit lambda form). Review addressed: #107454 (comment) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Contributor
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 21/21 (100.00%) | Lost baseline coverage: none · Uncovered code |
1 task done
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
`MatchImpl` supports a constant haystack with a non-constant needle (since the merge of ClickHouse#100479 into `master`), so the earlier exclusion of `LIKE`, `ILIKE`, `NOT LIKE`, `NOT ILIKE`, and `REGEXP` from the `SOME` / `ALL` array quantifier no longer applies: `'abc' LIKE SOME(['a%', 'b%'])` rewrites to `arrayExists(x -> 'abc' LIKE x, ['a%', 'b%'])` and evaluates without throwing. Route these predicates through the same `arrayExists` / `arrayAll` lambda rewrite as the keyword comparison predicates, correct the now-false parser comment and the operator documentation, and replace the `UNKNOWN_FUNCTION` assertion in the test with positive coverage (`LIKE` / `ILIKE` / `NOT LIKE` / `NOT ILIKE` / `REGEXP` with `SOME` / `ALL`, including `NULL` patterns and equivalence to the explicit lambda form). Review addressed: ClickHouse#107454 (comment) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
…s-distinct-from Support `IS DISTINCT FROM` / `IS NOT DISTINCT FROM` in the `SOME`/`ALL` array quantifier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #105129, which added the PostgreSQL-style
expr OP SOME(array)/expr OP ALL(array)array quantifier but rewrote it only for operators taggedOperatorType::Comparison(=,==,!=,<>,<=>,<,<=,>,>=).The review noted that the keyword predicates
IS DISTINCT FROM/IS NOT DISTINCT FROM(which carry the defaultOperatorType::None) were advertised but not actually routed through the rewrite, so e.g.1 IS DISTINCT FROM ALL([2, 3])was not recognised as the array quantifier.This routes
IS DISTINCT FROMandIS NOT DISTINCT FROMthrough thearrayExists/arrayAlllambda form as well, by peeking at the pending operator's function name (newLayer::previousOperator) in addition to itsOperatorType. The subquery ->IN/NOT INpath stays restricted to symbolic comparison operators, where it has meaning.The string-search predicates
LIKE,ILIKE,NOT LIKE,NOT ILIKE, andREGEXPare now supported by the array form too, rewritten to the samearrayExists/arrayAlllambdas:'abc' LIKE SOME(['a%', 'b%'])becomesarrayExists(x -> 'abc' LIKE x, ['a%', 'b%']). This works becauseMatchImplsupports a constant haystack with a non-constant needle (the lambda variable is the pattern argument), so it no longer throwsILLEGAL_COLUMN. They were excluded in an earlier revision of this PR, before that support was merged intomaster.Related: #105129
Review addressed: #105129 (comment)
Review addressed: #107454 (comment)
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The
SOME/ALLarray quantifier (expr OP SOME(array)/expr OP ALL(array)) now also supports the keyword comparison predicatesIS DISTINCT FROMandIS NOT DISTINCT FROM, and the string-search predicatesLIKE,ILIKE,NOT LIKE,NOT ILIKE, andREGEXP, rewritten toarrayExists/arrayAll.Documentation entry for user-facing changes
Version info
26.7.1.174(included in26.7and later)