Skip to content

Support IS DISTINCT FROM / IS NOT DISTINCT FROM in the SOME/ALL array quantifier - #107454

Merged
alexey-milovidov merged 8 commits into
masterfrom
any-all-arrays-is-distinct-from
Jun 27, 2026
Merged

alexey-milovidov merged 8 commits into
masterfrom
any-all-arrays-is-distinct-from

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jun 14, 2026 •

Copy link
Copy Markdown
Member

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 tagged OperatorType::Comparison (=, ==, !=, <>, <=>, <, <=, >, >=).

The review noted that the keyword predicates IS DISTINCT FROM / IS NOT DISTINCT FROM (which carry the default OperatorType::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 FROM and 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 now supported by the array form too, rewritten to the same arrayExists / arrayAll lambdas: 'abc' LIKE SOME(['a%', 'b%']) becomes arrayExists(x -> 'abc' LIKE x, ['a%', 'b%']). This works because MatchImpl supports a constant haystack with a non-constant needle (the lambda variable is the pattern argument), so it no longer throws ILLEGAL_COLUMN. They were excluded in an earlier revision of this PR, before that support was merged into master.

Related: #105129
Review addressed: #105129 (comment)
Review addressed: #107454 (comment)

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

The SOME / ALL array quantifier (expr OP SOME(array) / expr OP ALL(array)) now also supports the keyword comparison predicates IS DISTINCT FROM and IS NOT DISTINCT FROM, and the string-search predicates LIKE, ILIKE, NOT LIKE, NOT ILIKE, and REGEXP, rewritten to arrayExists / arrayAll.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.7.1.174 (included in 26.7 and later)

…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]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a98503f]

Summary: ✅


AI Review

Summary

This PR extends the SOME / ALL array quantifier rewrite to IS DISTINCT FROM, IS NOT DISTINCT FROM, and the LIKE / ILIKE / NOT LIKE / NOT ILIKE / REGEXP predicate family, with focused coverage for NULL semantics and basic string-search cases. The core rewrite looks consistent for the two-argument predicate forms, but the new LIKE-family support drops the existing ESCAPE syntax, so I am requesting changes.

Findings

⚠️ Majors

  • [src/Parsers/ExpressionListParsers.cpp:3455] The new string-search quantifier path recognizes LIKE / ILIKE / NOT LIKE / NOT ILIKE, but tryParseOperand consumes SOME(...) / ALL(...) before the existing ESCAPE handler can attach the third argument. As a result, a natural documented form such as SELECT '10%' LIKE SOME(['10|%']) ESCAPE '|'; is rejected instead of lowering to arrayExists(_a -> like('10%', _a, '|'), ['10|%']).
    Suggested fix: parse an optional ESCAPE clause after the array operand for the LIKE-family operators and include it in the lambda body, or explicitly document and test that this combination is unsupported.
Tests
  • ⚠️ Please add focused coverage for LIKE / ILIKE / NOT LIKE / NOT ILIKE with SOME / ALL plus ESCAPE, or a focused rejection/documentation test if the limitation is intentional.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: handle or explicitly document the LIKE-family ESCAPE interaction for the new array-quantifier rewrite.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Jun 14, 2026
alexey-milovidov and others added 2 commits June 16, 2026 12:45
… 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]>
alexey-milovidov and others added 3 commits June 19, 2026 17:43
…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]>
Comment thread src/Parsers/ExpressionListParsers.cpp Resolved
`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]>
Comment thread src/Parsers/ExpressionListParsers.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.30% 85.30% +0.00%
Functions 92.60% 92.60% +0.00%
Branches 77.60% 77.60% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 21/21 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@alexey-milovidov alexey-milovidov self-assigned this Jun 27, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Very good.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jun 27, 2026
Merged via the queue into master with commit 9add0e0 Jun 27, 2026
169 checks passed
@alexey-milovidov
alexey-milovidov deleted the any-all-arrays-is-distinct-from branch June 27, 2026 21:03
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 27, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants