Repository navigation
Pipelined SQL syntax - #101038
Pipelined SQL syntax#101038maVovk wants to merge 61 commits into
Conversation
|
Workflow [PR], commit [116c1a9] Summary: ❌
AI ReviewSummaryThis PR adds experimental pipe syntax ( Findings
Tests
Final VerdictStatus: |
…s_check The `Style check` job failed with `test_numbers_check`: `Gap (4356, 5018) > 100`. `check_gaps_in_tests_numbers` in `ci/jobs/check_style.py` rejects a gap of 100 or more between consecutive stateless test numbers, and `05018` sat 662 above the previous highest number (`04356`). Renumber the test to `04401`, the next free number after the current maximum on master (`04400`), keeping the gap within the threshold and avoiding a collision with master. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Pushed ChangeThe Renamed the test (a pure rename, No re-merge of |
The pipe `AGGREGATE` rewrite prepends each grouping expression that is not already present in the projection so grouping columns are surfaced in the output. An integer literal grouping key is a positional argument (see `replaceForPositionalArguments`): with `enable_positional_arguments = 1` it refers to an existing projection column, and with the setting off it is a constant grouping key. In neither case does the equivalent regular `SELECT` add it to the projection. Prepending such a literal both introduced a spurious leading column and shifted the positions that later positional arguments resolve against, so `FROM numbers(6) |> AGGREGATE number % 2 AS k, count() AS c GROUP BY 1` became effectively `SELECT 1, number % 2 AS k, count() AS c ... GROUP BY 1` and bound `GROUP BY 1` to the inserted literal instead of `number % 2`. Skip integer-literal grouping keys when prepending, so the pipe form produces the same AST as `SELECT number % 2 AS k, count() AS c FROM numbers(6) GROUP BY 1`. This also fixes negative positional arguments and out-of-range/aggregate positional errors to match the regular `SELECT`.
`04498_pipe_syntax_aggregate_positional_group_by` checks that positional `GROUP BY` arguments (with `enable_positional_arguments = 1`) resolve against the `AGGREGATE` projection exactly like the equivalent regular `SELECT`: `GROUP BY 1` binds to the first projection column, negative positions count from the end, an out-of-bounds position is rejected, and `EXPLAIN SYNTAX` of the pipe form is byte-identical to the regular `SELECT` (the positional key is preserved, no literal grouping column is prepended).
`master` has bumped to 26.7 (26.6 is already branched), so the setting is introduced in the 26.7 development cycle and its `SettingsChangesHistory` entry belongs in the 26.7 bucket rather than 26.6.
|
Merged Change (
|
…lyzer The `EXPLAIN SYNTAX` blocks in `04498_pipe_syntax_aggregate_positional_group_by` compare a positional `GROUP BY 1`. The old analyzer expands the positional argument in the `EXPLAIN SYNTAX` output (`GROUP BY modulo(number, 2) AS k`), while the new analyzer keeps `GROUP BY 1`, so the fixed `.reference` (generated with the new analyzer) does not match under the `old analyzer` CI configuration and the test failed with "result differs with reference". Add an `.oldanalyzer.reference` with the expanded `GROUP BY` rendering. The query results and the `GROUP BY 5` out-of-bounds rejection are analyzer-independent, so only the two `EXPLAIN SYNTAX` blocks differ. The pipe form still produces the same AST as the equivalent regular `SELECT`, so both `EXPLAIN SYNTAX` outputs are byte-identical under either analyzer.
…batches Address the review on `src/Parsers/parseQuery.cpp` (`splitMultipartQuery`): `SET allow_experimental_pipe_syntax = 1; FROM numbers(3) |> WHERE number > 0;` fails with a `SYNTAX_ERROR` on the PostgreSQL wire protocol (`PostgreSQLHandler`) and on `clickhouse benchmark` script input when the session started with the setting off. Both of these paths call `splitMultipartQuery`, which splits (parses) the whole batch up front, before any statement runs, using a single `allow_pipe_syntax` snapshot. So the leading `SET` cannot enable pipe parsing for the following `|>` statement. This is the same pre-existing limitation that already applies to `implicit_select` and `allow_settings_after_format_in_insert` on these paths. The regular `clickhouse-client` is unaffected: `analyzeMultiQueryText` parses and executes one statement at a time and re-reads the setting between statements. Rather than restructuring the two batch handlers to interleave parsing and execution (out of scope for an experimental feature), document the limitation in the pipe-syntax page and advise enabling the setting at the session/connection level. Pin the behavior with a `splitMultipartQuery` gtest case.
|
Merged Fix:
|
# Conflicts: # src/Server/GRPCServer.cpp
…ouse-format A pipe query accepted by normal execution and by `formatQuery` could not be highlighted with `highlightQuery` (the `QueryTokenizationSettings` struct did not carry the setting) and could not be formatted with `clickhouse-format` (no CLI option, old `ParserQuery` constructor). Thread the setting through both entry points and add a test covering `clickhouse-format --allow_experimental_pipe_syntax`, `formatQuery`, and `highlightQuery`.
`ParserPipeAggregate` already parses `GROUP BY ROLLUP`/`CUBE`/`GROUPING SETS`/`ALL` and the trailing `WITH ROLLUP`/`WITH CUBE`/`WITH TOTALS` forms, but the docs listed them as unsupported. Document them as supported and add a test asserting each form produces the same rows as the equivalent regular `SELECT` (verified under both analyzers). Also document that query-string tooling honors `allow_experimental_pipe_syntax`.
|
Merged Wire
|
# Conflicts: # ci/jobs/scripts/check_style/experimental_settings_ignore.txt
`AGGREGATE` documents its output as the grouping columns followed by the
aggregate expressions, but the dedup logic only suppressed duplicates: a
grouping key the user had already projected *after* an aggregate stayed where
it was written. So
FROM numbers(5) |> AGGREGATE count() AS c, number % 3 AS k GROUP BY k |> ORDER BY 1
sorted by the aggregate `c` instead of by the grouping column `k`.
An already-projected grouping expression is now moved to the front instead of
being left in place, so the projection is the grouping columns in `GROUP BY`
order followed by the remaining expressions, regardless of how the user wrote
them. A grouping expression the projection does not produce is still added in
front, as before.
Reordering is skipped entirely when any grouping argument is positional (an
integer literal): both adding and moving columns would shift the positions such
an argument resolves against. Previously only the positional argument itself was
skipped, so a mixed list such as `GROUP BY 2, number % 3` could still shift the
projection. `GROUP BY ALL` does not spell out the grouping keys and keeps the
written order; both exceptions are now documented.
Test `04647_pipe_syntax_aggregate_output_column_order`.
A dictionary source query is a top-level query of its own, but it was re-parsed twice before execution by parsers that never accepted pipe syntax, so `SOURCE(CLICKHOUSE(QUERY 'FROM ... |> ...'))` was rejected with a syntax error even when the setting was enabled: - `ClickHouseDictionarySource::createStreamForQuery` validated the query with a one-argument `ParserQuery`. It now passes `allow_experimental_pipe_syntax` from the dictionary source context, which is where the check belongs. - `DDLDependencyVisitor::tryVisitNestedSelect` extracted the source query's table dependencies with `ParserSelectWithUnionQuery`. It now also accepts a pipelined query. This is analysis, not enforcement: it runs against the global context, which does not carry the dictionary's settings, so gating there would reject queries the execution path accepts. `ParserPipelinedQuery` produces the same `ASTSelectWithUnionQuery`, so the visitor is unaffected otherwise. The setting is read from the dictionary source context - server defaults plus the dictionary's own `SETTINGS(...)` clause - and not from the session, which is now documented in the pipe syntax limitations. Test `04648_pipe_syntax_dictionary_source`.
…bucket Master is now `26.8` (`26.7` has been branched), so the not-yet-released setting belongs in the current bucket.
|
Maintenance round: merged Major 1 — The dedup logic only suppressed duplicates, so a grouping key the user projected after an aggregate stayed where it was written and Reordering is now skipped for the whole grouping list as soon as one argument is positional, not just for that argument: a mixed list such as Test Major 2 — dictionary source queries (
Consequence worth noting: the setting has to be enabled for the dictionary itself, in its Also moved The remaining Nit ( All six |
| { | ||
| ParserPipelinedQuery pipelined_parser(/*allow_pipe_syntax_=*/ true); | ||
| ParserSelectWithUnionQuery select_parser; | ||
| return pipelined_parser.parse(pos, node, expected) || select_parser.parse(pos, node, expected); |
There was a problem hiding this comment.
ParserDictionarySourceQuery is still narrower than the execution path here. ClickHouseDictionarySource::createStreamForQuery validates dictionary source queries with full ParserQuery, so a source like FROM src |> WHERE x SETTINGS max_threads = 1 is valid when allow_experimental_pipe_syntax = 1. In this dependency-extraction path, though, ParserPipelinedQuery stops before the trailing SETTINGS and there is no ParserQueryWithOutput wrapper to consume it, so parseQuery rejects the same query with SYNTAX_ERROR.
That means a valid pipe-syntax dictionary source can still fail in CREATE DICTIONARY / startup dependency analysis (can_throw = true), or silently lose loading dependencies when can_throw = false. Please parse dictionary source queries through a pipe-aware top-level query parser, or at least consume trailing query SETTINGS here too, so analysis accepts everything execution accepts.
| return false; | ||
| } | ||
|
|
||
| if (s_with.ignore(pos, expected)) |
There was a problem hiding this comment.
This only accepts one trailing WITH ... modifier plus an optional second WITH TOTALS, but regular GROUP BY parsing accepts the modifiers in any order via the while (s_with.ignore(...)) loop in ParserSelectQuery.
For example, SELECT number % 2 AS k, count() AS c FROM numbers(6) GROUP BY k WITH TOTALS WITH CUBE is accepted by the regular SELECT parser and sets the same flags as WITH CUBE WITH TOTALS, while the pipe form fails here on the second WITH with SYNTAX_ERROR. That breaks the "same AST as regular SELECT" contract for AGGREGATE.
Please mirror the regular while (WITH ...) logic here instead of hard-coding the ROLLUP/CUBE then TOTALS order.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 483/593 (81.45%) · Uncovered code |
|
Continued in #111151. |
Changelog category:
Changelog entry:
Parser supports pipelined SQL syntax introduced by Google [1]. This syntax allows users to build queries top-to-bottom instead of current inside-out flow. Comparison of syntaxes can be found below.
allow_experimental_pipe_syntaxsetting enablesParserPipelinedQuerywhich for now supports filters, sortings, limitings, aggregations and joins. Parser produces the same AST as default parser so no changes on optimizer and executor is needed.Related issue: #69364
Documentation entry for user-facing changes
Pipe syntax adds a
|>operator that allows users to process data sequentially. Queries start with standaloneFROMclause and connect operators with pipes|>. Scope of subsequent clause is limited to output of previous operator.Settings:
allow_experimental_pipe_syntax- enables parsing of|>pipe operators (default = false)Supported operations:
|> WHERE <expr>- apply filters on rows|> ORDER BY <expr>- apply sorting|> LIMIT <n> [OFFSET <m>]- truncate output|> AGGREGATE <agg_expr>- full-table aggregation|> AGGREGATE <agg_expr> GROUP BY <grouping_expr>- aggregation with grouping|> [LEFT|...] JOIN <table_expr> [ON <condition>]- join operationExamples:
Query with standard SQL syntax
Pipelined equivalent
TPC-H 13 query translation:
[1] - SQL Has Problems. We Can Fix Them: Pipe Syntax in SQL