mirror of
https://github.com/hanzoai/datastore.git
synced 2026-09-26 13:55:07 +00:00
`UNNEST(...) WITH ORDINALITY` is valid PostgreSQL table-function syntax that adds a 1-based ordinality column. `ARRAY JOIN` has no direct equivalent, and `WITH` is not a clause keyword in `_NOT_AN_ALIAS`, so the omitted-`AS` alias parser in `rewrite_arrayjoin_to_array_join` accepted the bare `WITH` token as the table alias and emitted invalid ClickHouse SQL, e.g. SELECT * FROM t CROSS JOIN UNNEST(arr) WITH ORDINALITY AS u(x, n) became SELECT * FROM t ARRAY JOIN arr AS WITH ORDINALITY AS u(x, n) which would make the benchmark count a rewriter artifact as a ClickHouse query failure. Add a guard that detects `WITH ORDINALITY` before alias parsing and leaves the whole construct unchanged, consistent with the conservative handling of other shapes `ARRAY JOIN` cannot represent (`RIGHT`/`FULL` joins, real `ON` predicates, `USING` clauses). Add regression tests for `FROM`, `JOIN`, `LEFT JOIN`, and lowercase forms, plus a sanity check that the plain `UNNEST(arr) AS u(x)` rewrite is unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>