Repository navigation
Add unnest as alias of arrayJoin - #105124
Conversation
PostgreSQL's `unnest(arr)` in a `SELECT` clause behaves the same as ClickHouse's `arrayJoin(arr)` — one row per array element. Expose `unnest` as a case-insensitive alias to spare PostgreSQL-dialect queries a rewrite for the common case. Note that PostgreSQL's `LATERAL`/`CROSS JOIN UNNEST(...)` table-source syntax is not affected by this alias and still requires `ARRAY JOIN`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Workflow [PR], commit [cb7fb90] Summary: ✅ AI ReviewSummaryThis PR adds Findings
Tests
Final Verdict
|
Recent compatibility PRs added case-insensitive aliases and parser sugar that make several of the SQLStorm rewrites unnecessary: - `STDDEV` -> `stddevPop` (#105120) - `array_to_string` -> `arrayStringConcat` (#105121) - `REGEXP_SUBSTR` -> `regexpExtract` (#105122) - `CARDINALITY` -> `length` (#105123) - `unnest()` function -> `arrayJoin()` (#105124) - `STRING_AGG` -> `groupConcat` (#105125) - `date_part(unit,e)` -> `EXTRACT(unit FROM e)` (#105127) - `expr OP ANY/ALL(array_literal)` (#105129) `ARRAY_AGG`, `TRANSLATE`, and `EXTRACT(EPOCH|DOW|... FROM ...)` were already supported by ClickHouse before these PRs. Removed the corresponding rewrite calls and helper functions (`rewrite_string_agg`, `rewrite_array_agg`, `rewrite_date_part`, `rewrite_stddev`, `rewrite_extract_epoch`, the EXTRACT(DOW) inline rewrite, `rewrite_any_comparison`, and the trailing `unnest(...) -> arrayJoin(...)` substitution). Also dropped the unreferenced no-op helpers (`rewrite_extract_unit`, `rewrite_fetch_offset`, `rewrite_interval`, `rewrite_cast_timestamp`, `rewrite_current_timestamp`, `rewrite_bool_literals`, `rewrite_ilike`, `rewrite_no_supertype`). The PostgreSQL `LATERAL` / `CROSS JOIN UNNEST(...)` table-source forms, `arrayJoin(...)` in JOIN position, PG-specific casts, `AT TIME ZONE`, `STRING_AGGDistinct` (a mangled-name artifact), and the still-unsupported function rewrites (`string_to_array`, `regexp_split_to_array`, `RANDOM`, `TO_TIMESTAMP`, `ARRAY_LENGTH`, `SPLIT_PART`, `age`) are still rewritten. Net change: -329 lines from rewrite_queries.py and -75 lines from the tests (the `TestRewriteAnyComparison` class is removed since the rewrite it covered no longer exists). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
| /// the same as `arrayJoin(arr)` - one row per array element. Note that | ||
| /// PostgreSQL's `LATERAL`/`CROSS JOIN UNNEST(...)` table-source syntax is | ||
| /// not supported by this alias and still requires `ARRAY JOIN`. | ||
| factory.registerAlias("unnest", "arrayJoin", FunctionFactory::Case::Insensitive); |
There was a problem hiding this comment.
unnest is registered only as a FunctionFactory alias, but the legacy AST pipeline still has hard-coded checks for "arrayJoin" (for example in ActionsVisitor::visit(const ASTFunction ...)). With enable_analyzer = 0 and normalize_function_names = 0, unnest([1, 2]) is handled as a regular function call instead of an ARRAY JOIN action, then FunctionArrayJoin::executeImpl throws FUNCTION_IS_SPECIAL.
Could we make legacy handling independent of name normalization (or explicitly treat unnest as arrayJoin in special-function checks) and add a regression test for:
SET enable_analyzer = 0, normalize_function_names = 0;
SELECT unnest([1, 2]);There was a problem hiding this comment.
We are not interested in the legacy analysis at all. Ok to skip the comment above.
LLVM Coverage Report
Changed lines: 100.00% (4/4) · Uncovered code |
PostgreSQL's
unnest(arr)in aSELECTclause behaves the same as ClickHouse'sarrayJoin(arr)— one row per array element. Adding a case-insensitive alias spares PostgreSQL-dialect queries a rewrite for the common case.Note: PostgreSQL's
LATERAL/CROSS JOIN UNNEST(...)table-source syntax is not affected by this alias and still requiresARRAY JOIN— that is a parser-level change for a separate PR.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added
unnestas a case-insensitive alias ofarrayJoinfor PostgreSQL compatibility (function-call form).Documentation entry for user-facing changes
Version info
26.5.1.724