Skip to content

Pipelined SQL syntax#101038

Open
maVovk wants to merge 19 commits intoClickHouse:masterfrom
maVovk:pipelined_syntax
Open

Pipelined SQL syntax#101038
maVovk wants to merge 19 commits intoClickHouse:masterfrom
maVovk:pipelined_syntax

Conversation

@maVovk
Copy link
Copy Markdown

@maVovk maVovk commented Mar 28, 2026

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
Copy link
Copy Markdown

CLAassistant commented Mar 28, 2026

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
Copy link
Copy Markdown
Contributor

clickhouse-gh bot commented Mar 28, 2026

Workflow [PR], commit [06b9617]

Summary:

job_name test_name status info comment
Stateless tests (arm_asan_ubsan, flaky check) failure
03668_shard_join_in_reverse_order FAIL cidb, issue
Stateless tests (amd_msan, flaky check) failure
03668_shard_join_in_reverse_order FAIL cidb, issue
03668_shard_join_in_reverse_order FAIL cidb, issue
Stateless tests (amd_debug, flaky check) failure
03668_shard_join_in_reverse_order FAIL cidb, issue
03668_shard_join_in_reverse_order FAIL cidb, issue
Stress test (arm_msan) failure
Server died FAIL cidb
MemorySanitizer: use-of-uninitialized-value (STID: 1003-358c) FAIL cidb, issue

AI Review

Summary
This PR adds experimental pipelined SQL syntax (|>) behind allow_experimental_pipe_syntax, wires parser settings through client/server/query entry points, and adds parser reordering tests. I reviewed parser semantics, setting propagation paths, and backward-compatibility wiring. I did not find any new high-confidence correctness/safety/performance issues beyond already-discussed review threads.

ClickHouse Rules

Item Status Notes
Deletion logging
Serialization versioning
Core-area scrutiny
No test removal
Experimental gate
No magic constants
Backward compatibility
SettingsChangesHistory.cpp
PR metadata quality
Safe rollout
Compilation time

Final Verdict

  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh bot added the pr-experimental Experimental Feature label Mar 28, 2026
const char * end_,
bool allow_settings_after_format_in_insert_ = false,
bool implicit_select_ = false,
bool allow_pipe_syntax_ = false)
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.

ParserQuery now accepts allow_pipe_syntax, but this callsite still uses the 2-argument constructor, so allow_experimental_pipe_syntax is silently ignored in gRPC requests.

Impact: pipe queries (FROM ... |> ...) parse fine via normal server/client paths, but fail with syntax exception over gRPC even when the setting is enabled.

Please pass the setting explicitly here too, e.g.:

ParserQuery parser(
    end,
    settings[Setting::allow_settings_after_format_in_insert],
    settings[Setting::implicit_select],
    settings[Setting::allow_experimental_pipe_syntax]);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Need some more context in order to fix this. There are 20+ files where ParserQuery is used, I don't think that I need to introduce this feature flag everywhere(in other dialects parsers, fuzz queries etc.). Moreover, other 2 parser options are absent sometimes.
Added feature flag in GRPCServer.cpp, but maybe that not enough

@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh bot commented Apr 1, 2026

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.00% 84.00% +0.00%
Functions 90.90% 90.90% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 69.38% (417/601) | lost baseline coverage: 8 line(s) · Uncovered code

Full report · Diff report

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.

3 participants