Skip to content

Pipelined SQL syntax - #101038

Closed
maVovk wants to merge 61 commits into
ClickHouse:masterfrom
maVovk:pipelined_syntax
Closed

maVovk wants to merge 61 commits into
ClickHouse:masterfrom
maVovk:pipelined_syntax

Conversation

@maVovk

@maVovk maVovk commented Mar 28, 2026 •

Copy link
Copy Markdown

Changelog category:

  • Experimental Feature

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_syntax setting enables ParserPipelinedQuery which 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 standalone FROM clause 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 operation

Examples:

Query with standard SQL syntax

SELECT * FROM (
    SELECT number % 2 AS k, count() AS c
    FROM numbers(6)
    GROUP BY number % 2
) WHERE k = 1;

Pipelined equivalent

FROM numbers(6)
|> AGGREGATE number % 2 AS k, count() AS c GROUP BY number % 2
|> WHERE k = 1;

TPC-H 13 query translation:

:) set allow_experimental_pipe_syntax=1;
:) ... # initialize TPC-H databases
:) FROM customer
   |> LEFT OUTER JOIN orders ON c_custkey = o_custkey AND o_comment NOT LIKE '%special%requests%'
   |> AGGREGATE COUNT(o_orderkey) AS c_count GROUP BY c_custkey
   |> AGGREGATE COUNT(*) AS custdist GROUP BY c_count
   |> ORDER BY custdist DESC, c_count DESC;

SELECT c_count, COUNT(*) AS custdist
FROM
(
    SELECT
        c_custkey, COUNT(o_orderkey) AS c_count
    FROM customer
    LEFT JOIN orders ON (c_custkey = o_custkey) AND (o_comment NOT LIKE '%special%requests%')
    GROUP BY c_custkey
) AS _pipe_subquery_0
GROUP BY c_count
ORDER BY custdist DESC, c_count DESC

[1] - SQL Has Problems. We Can Fix Them: Pipe Syntax in SQL

@CLAassistant

CLAassistant commented Mar 28, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Mar 28, 2026
@clickhouse-gh

clickhouse-gh Bot commented Mar 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [116c1a9]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_llvm_coverage, old analyzer, s3 storage, DBReplicated, WasmEdge, parallel, 2/3) FAIL
04627_analyzer_compatibility_final_all_joined_tables FAIL cidb

AI Review

Summary

This PR adds experimental pipe syntax (FROM ... |> ...) and threads it through more user-facing entry points, including dictionary sources and query-string tooling. The current head is much closer, but there are still two parser-compatibility gaps where valid pipe queries do not follow the same contract as the equivalent regular SELECT, so the review remains at request changes.

Findings

⚠️ Majors

  • [src/Databases/DDLDependencyVisitor.cpp:591] Dictionary-source dependency extraction still parses with ParserPipelinedQuery/ParserSelectWithUnionQuery directly instead of the same top-level parser used by execution. A source query such as FROM src |> WHERE x SETTINGS max_threads = 1 is accepted by ClickHouseDictionarySource::createStreamForQuery, but this dependency-analysis path rejects it because the trailing query SETTINGS are never consumed. Suggested fix: use a pipe-aware top-level query parser here, or explicitly consume trailing query SETTINGS so analysis accepts every dictionary source query that execution accepts.
  • [src/Parsers/ParserPipeOperators.cpp:322] Pipe AGGREGATE only accepts one trailing WITH ... modifier plus an optional second WITH TOTALS, while regular GROUP BY parsing accepts trailing modifiers in any order. That means a regular SELECT shape such as ... GROUP BY k WITH TOTALS WITH CUBE is accepted by the normal parser but still fails in pipe syntax with SYNTAX_ERROR, so the pipe form no longer produces the same AST/error surface as the equivalent SELECT. Suggested fix: mirror the regular ParserSelectQuery loop over repeated WITH modifiers instead of hard-coding the ROLLUP/CUBE then TOTALS order.
Tests
  • ⚠️ Add a dictionary-source regression covering a local SOURCE(CLICKHOUSE(QUERY 'FROM ... |> ... SETTINGS ...')) query, so dependency extraction is exercised on the same top-level grammar that execution accepts.
  • ⚠️ Add a parser/AST regression for repeated trailing WITH modifiers on pipe AGGREGATE (for example WITH TOTALS WITH CUBE), compared against the equivalent regular SELECT.
Final Verdict

Status: ⚠️ Request changes

@clickhouse-gh clickhouse-gh Bot added the pr-experimental Experimental Feature label Mar 28, 2026
Comment thread src/Parsers/ParserPipelinedQuery.cpp Resolved
Comment thread src/Parsers/ParserPipelinedQuery.cpp Resolved
Comment thread src/Parsers/ParserPipelinedQuery.cpp Resolved
Comment thread src/Parsers/ParserPipelinedQuery.cpp Resolved
Comment thread src/Parsers/ParserQuery.h Resolved
Comment thread src/Parsers/ParserPipelinedQuery.cpp Resolved
…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]>
@alexey-milovidov

Copy link
Copy Markdown
Member

Pushed a6f193d6491 to fix the only red check.

Change

The Style check job failed test_numbers_check with 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 the new 05018_pipe_syntax_top_level_only test sat 662 above the previous highest number (04356), so the gate failed and dropped every downstream job.

Renamed the test (a pure rename, .sql + .reference, no content change) to 04401_pipe_syntax_top_level_only, the next free number after the current maximum on master (04400). The gap from 04356 to 04401 is 45, within the threshold, and 04401 does not collide with any existing test on master or on the branch. Verified locally that check_gaps_in_tests_numbers reports no large gaps after the rename.

No re-merge of master: the branch is ~580 commits behind but the merge base is only ~1 day old, and the failure was a self-inflicted test-number gap that master does not fix. All review threads remain resolved and no Request changes verdict is outstanding.

Comment thread src/Parsers/ParserPipeOperators.cpp Resolved
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.
@alexey-milovidov

Copy link
Copy Markdown
Member

Merged master (the branch was ~90k commits / 10 days behind) and addressed the remaining Request changes review item (positional GROUP BY in the AGGREGATE rewrite).

Change (6353023cbf4)

The pipe AGGREGATE rewrite prepends each grouping expression 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 already 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. Integer-literal grouping keys are now skipped 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.

Test (ac1a5c85d60)

04498_pipe_syntax_aggregate_positional_group_by verifies, with enable_positional_arguments = 1, that the pipe form matches the equivalent regular SELECT: GROUP BY 1 binds to the first projection column, negative positions (GROUP BY -3, -2) count from the end of the projection, an out-of-bounds position is rejected with BAD_ARGUMENTS, and EXPLAIN SYNTAX of the pipe form is byte-identical to the regular SELECT (the positional key is preserved and no literal grouping column is prepended).

Settings history (48418e0dd5b)

master has bumped to 26.7 (26.6 is already branched), so allow_experimental_pipe_syntax was moved to the 26.7 SettingsChangesHistory bucket.

CI on the previous head

The only red check was Performance Comparison (arm_release, master_head, 2/6) → Check Results = "Errors while building the report" — a report-generation infrastructure error, not a query regression (the Cloud Performance Report AI verdict on the same head was no_change across 38 queries). It should clear on the fresh run.

Comment thread src/Parsers/parseQuery.cpp Resolved
…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.
@alexey-milovidov

Copy link
Copy Markdown
Member

Merged master (the branch was ~2532 commits / ~8 days behind — a clean merge) and addressed the CI failure and the outstanding AI review finding.

Fix: 04498_pipe_syntax_aggregate_positional_group_by under the old analyzer (f05b8f88072)

The only red test on the previous head, failing in Stateless tests (amd_llvm_coverage, old analyzer, …). The two EXPLAIN SYNTAX blocks compare a positional GROUP BY 1. The old analyzer expands the positional argument in EXPLAIN SYNTAX output while the new analyzer (which generated the reference) keeps GROUP BY 1:

-GROUP BY 1
+GROUP BY modulo(number, 2) AS k

Added an .oldanalyzer.reference with the expanded rendering. The query results and the GROUP BY 5 out-of-bounds rejection are analyzer-independent, and the pipe form still produces the same AST as the equivalent regular SELECT, so both EXPLAIN SYNTAX outputs stay byte-identical under either analyzer.

splitMultipartQuery multi-statement batch (AI Major on parseQuery.cpp) — f2da026692d

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 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 affect parsing of 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 two 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), I documented the limitation in the pipe-syntax page and advise enabling the setting at the session/connection level, and pinned the behavior with a splitMultipartQuery gtest case (SplitMultipartQuery.PipeSyntaxSettingIsSnapshotForWholeBatch).

ClientBaseHelpers highlighting/formatting (AI Major, previously dismissed)

Left as-is — this is a cosmetic-only gap and execution is correctly wired:

  • ClientBase::parseQuery (ClientBase.cpp:480) constructs ParserQuery with allow_experimental_pipe_syntax, so pipe queries run fine in clickhouse-client.
  • formatQuery (ClientBaseHelpers.cpp:680) is a best-effort client-side formatter that deliberately hardcodes all parser settings (allow_settings_after_format_in_insert = false, implicit_select = false); its only caller (ReplxxLineReader) has no settings context, so special-casing pipe syntax there would be inconsistent with the function's design.
  • highlightText (ClientBaseHelpers.cpp:294) is interactive syntax highlighting; it degrades gracefully (no color for |>) without affecting execution. It does thread implicit_select from context, so it could be extended to pass allow_experimental_pipe_syntax if we want the highlighter to recognize pipe queries — happy to add that one line if preferred.

CI

Head d7f082a76eb. The only previously-red test is fixed by the .oldanalyzer.reference; a fresh run is validating.

Comment thread src/Functions/formatQuery.cpp Resolved
…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`.
@alexey-milovidov

Copy link
Copy Markdown
Member

Merged master (the branch was CONFLICTING; one trivial conflict in src/Server/GRPCServer.cpp — both sides add a setting declaration, kept both) and addressed both open review items from the AI review.

Wire allow_experimental_pipe_syntax through query-string tooling (b3fbc8fea8c)

The "Minimum required actions" item. A pipe query accepted by normal execution and by formatQuery could not be highlighted with highlightQuery and could not be formatted with clickhouse-format:

  • QueryTokenizationSettings now carries allow_pipe_syntax, populated from the context and passed to the ParserQuery constructor in highlightQuery (tokenizeQuery is a pure lexer and needs nothing).
  • clickhouse-format exposes --allow_experimental_pipe_syntax (via cmd_settings.addToProgramOptions, same mechanism as max_parser_depth) and passes it to ParserQuery.
  • New test 04612_pipe_syntax_query_string_tooling: clickhouse-format rejects pipe syntax without the option and formats it (multi-line and --oneline) with it; formatQuerySingleLine/formatQueryOrNull and highlightQuery honor the session setting on and off.

Document and test GROUP BY modifiers in pipe AGGREGATE (0ddf6a4803a)

The docs nit: ParserPipeAggregate already parses GROUP BY ROLLUP/CUBE/GROUPING SETS/ALL and trailing WITH ROLLUP/WITH CUBE/WITH TOTALS, while the Limitations section claimed those forms do not exist. Chose "document and test as supported" over rejecting them, since they map one-to-one onto the regular ASTSelectQuery flags and need no extra rewrite logic. The syntax block, the AGGREGATE operator description, and the Limitations section are updated, and the new test 04613_pipe_syntax_aggregate_group_by_modifiers asserts each form produces the same rows as the equivalent regular SELECT (verified locally under both the new and the old analyzer).

Both review threads are resolved. Built the clickhouse binary and generated the test references from real runs on it.

Comment thread src/Parsers/ParserPipeOperators.cpp Resolved
# 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.
@alexey-milovidov

Copy link
Copy Markdown
Member

Maintenance round: merged master (one trivial conflict in experimental_settings_ignore.txt, both entries kept), addressed both AI-Review Majors and both requested tests, and pushed 0ddf6a4803a..116c1a9813d.

Major 1 — AGGREGATE output column order (b7cdb3a19d1)

The dedup logic only suppressed duplicates, so a grouping key the user projected after an aggregate stayed where it was written and |> ORDER BY 1 sorted by the aggregate. An already-projected grouping expression is now moved to the front rather than left in place, so the projection is always the grouping columns in GROUP BY order followed by the remaining expressions:

FROM numbers(5) |> AGGREGATE count() AS c, number % 3 AS k GROUP BY k
  →  SELECT modulo(number, 3) AS k, count() AS c FROM numbers(5) GROUP BY k

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 GROUP BY 2, number % 3 could previously still shift the positions the literal resolves against. GROUP BY ALL does not spell out its grouping keys, so it keeps the written order — documented as an explicit exception rather than guessing which projection entries are aggregates in the parser.

Test 04647_pipe_syntax_aggregate_output_column_order covers aggregate-before-key, alias and alias-less matching, multi-key order, the not-projected case, positional and mixed-positional grouping, and GROUP BY ALL; each case asserts both EXPLAIN SYNTAX and the rows, with an .oldanalyzer.reference for the EXPLAIN SYNTAX rendering difference.

Major 2 — dictionary source queries (afba9f6ee9c)

ClickHouseDictionarySource::createStreamForQuery now passes allow_experimental_pipe_syntax from the dictionary source context. That alone was not enough: DDLDependencyVisitor::tryVisitNestedSelect re-parses the source query with ParserSelectWithUnionQuery to extract table dependencies and rejected the pipe query first. It now also accepts a pipelined query (same ASTSelectWithUnionQuery, so the visitor is unchanged otherwise). That path is analysis rather than 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; the check stays in createStreamForQuery.

Consequence worth noting: the setting has to be enabled for the dictionary itself, in its SETTINGS(...) clause or as a server default, not with a session SET — the dictionary source context is built from the server defaults plus that clause. Documented in the limitations. Test 04648_pipe_syntax_dictionary_source covers the working dictionary and the SYNTAX_ERROR on load without the setting.

Also moved allow_experimental_pipe_syntax from the 26.7 to the 26.8 settings-history bucket (116c1a9813d), since 26.7 has been branched.

The remaining Nit (ClientBaseHelpers.cpp) is left as previously dismissed — it is highlighting/formatting only, execution is correctly wired.

All six pipe_syntax tests pass locally under both analyzers on a freshly built binary.

{
ParserPipelinedQuery pipelined_parser(/*allow_pipe_syntax_=*/ true);
ParserSelectWithUnionQuery select_parser;
return pipelined_parser.parse(pos, node, expected) || select_parser.parse(pos, node, expected);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@clickhouse-gh

clickhouse-gh Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.30% 86.30% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 78.40% 78.40% +0.00%

Changed lines: Changed C/C++ lines covered: 483/593 (81.45%) · Uncovered code

Full report · Diff report

@alexey-milovidov

Copy link
Copy Markdown
Member

Continued in #111151.

@alexey-milovidov alexey-milovidov self-assigned this Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-experimental Experimental Feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants