Repository navigation
Add pipelined operators - #73394
Add pipelined operators#73394itsWill wants to merge 5 commits into
Conversation
|
Guilherme Mansur seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
rschu1ze
left a comment
There was a problem hiding this comment.
Thanks for this PR, I like the direction it is taking.
Please find some comments inline.
Regarding your question about aggregation, I second the CTE approach.
About integrating this PR: My main concern is to keep the "blast radius" as small as possible and that means introducing a setting or dialect which isolates pipe syntax from normal SQL. If you do that, and maybe try to add a few other basic and useful operators (ORDER BY, SELECT, maybe JOIN comes to mind) + add some SQL tests (--> tests/queries/0_stateless/), then we can happily merge this PR.
| ast = parseQuery(parser, begin, end, "", max_query_size, settings[Setting::max_parser_depth], settings[Setting::max_parser_backtracks]); | ||
|
|
||
| #ifndef NDEBUG | ||
| if(settings[Setting::dialect] == Dialect::clickhouse) |
There was a problem hiding this comment.
We should definitely have a separate Dialect enum value clickhouse_with_pipes and introduce a separate if branch similar to l. 861-876.
| add_headers_and_sources(clickhouse_parsers ./Kusto) | ||
| add_headers_and_sources(clickhouse_parsers ./PRQL) | ||
| add_headers_and_sources(clickhouse_parsers ./Kusto/KustoFunctions) | ||
| add_headers_and_sources(clickhouse_parsers ./ZetaSQL) |
There was a problem hiding this comment.
I had a look at Google's ZetaSQL repository. My understanding is this:
- it provides a C++ parser for Google's unified SQL dialect (used by their various internal databases)
- the parser produces an AST which the individual databases then interpret in various ways (*)
- the repository comes with an
executebinary which implements a extremely simple end-to-end executor for SQL queries on a small set of predefined tables (which makes this a nice utility for testing) - the SQL dialect is documented at great detail at literal/identifier/keyword level including SQL operators and functions for DDL/DML (
CREATE/UPDATE/DELETE) and DQL (SELECT)
The idea of integrating ZetaSQL as a submodule into ClickHouse and going the (*) route has charme but it seems very difficult due to two reasons: 1. ZetaSQL is open-source but they are seemingly not interested in building a community around it, nor that databases outside Google add ZetaSQL as a frontend. The README says they don't even accept pull requests. 2. ClickHouse's existing and their SQL dialects differ in the details, using ZetaSQL as a frontend would create unnecessary surprises for users.
Now that this is out of the way :-) my suggestion is this: We can give credits and link the research paper https://research.google/pubs/pub1005959/ but I'd avoid the term "ZetaSQL" (here, and elsewhere in this PR), and instead call the dialect ClickhouseWithPipes or something similar.
There was a problem hiding this comment.
This is a good point, I'll refactor this to be under a more general setting ClickHouseWithPipes type setting.
| if (pos < end && *pos == '|') | ||
| return Token(TokenType::Concatenation, token_begin, ++pos); | ||
|
|
||
| if (pos < end && *pos == '>') |
There was a problem hiding this comment.
Whatever code we add or change, we should do all modifications under a special setting allow_experimental_pipe_syntax etc. (please define such a settings, --> src/Core/Settings.cpp). One could argue that the pipe syntax is only used if SET dialect = [...] was ran before, but for example here, the standard dialect is parsed slightly different as well and we should avoid edge cases that break queries which previously worked fine.
| ParserExternalDDLQuery external_ddl_p; | ||
| ParserTransactionControl transaction_control_p; | ||
| ParserDeleteQuery delete_p; | ||
| ZetaSQL::ParserZetaSQLQuery zetasql_parser; |
There was a problem hiding this comment.
Not sure ... afaik, ZetaSQL pipe syntax only applies to SELECT-type queries. Perhaps we should move the ZetaSQL parser into ParserSelectQuery (l. 82)?
EDIT: after digging a bit more (see my other comment above), I think we better don't modify this file at all and instead introduce a new if branch for a new dialect in executeQuery.cpp
| #include "Parsers/ZetaSQL/ParserFromStatement.h" | ||
| #include "Parsers/ZetaSQL/ParserPipe.h" | ||
|
|
||
| namespace DB::ZetaSQL { |
There was a problem hiding this comment.
(Cosmetic: Let's use namespace DB instead of DB::ZetaSQL - the ClickHouse codebase generally avoids nested namespaces.)
| ASTPtr expression; | ||
| }; | ||
|
|
||
| std::list<PipelineStage> stages; |
There was a problem hiding this comment.
std::list<PipelineOperators> operators? That would be the official syntax at least.
|
Dear @itsWill, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
1 similar comment
|
Dear @itsWill, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Actually, it does almost what I expected... |
|
Dear @itsWill, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
That's a very good feature, and we should continue. |
|
Dear @itsWill, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
3 similar comments
|
Dear @itsWill, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @itsWill, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @itsWill, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @itsWill, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
It's strange that we implement it manually as a separate dialect, yet name it ZetaSQL — while not using the What I actually want is to implement pipeline operators as a syntax extension in the regular ClickHouse dialect. Then any type of query can be pipelined, and inside every stage, the ClickHouse dialect is used. The resulting AST will be the same as an AST with multiple nested subqueries. Compatibility with BigQuery is not a concern. |
|
The approach described in the comment above is now implemented in #111151: pipe operators as a syntax extension of the regular ClickHouse dialect, without a separate dialect or translator. Each Thank you for the initial implementation and for exploring the design space - the new PR supersedes this one. |
Changelog category (leave one):
This is a proof of concept of a possible approach for adding the ZetaSQL piped syntax into ClickHouse: #69364
The high level overview of the approach is:
ZetSQLQueryParserparses the piped synax into a ZetaSQL Specific Syntax tree.In practice it looks like this on the console:
The main advantages of doing this approach are:
EXTENDor different interpretations of standard SQL, like being able to start a statement using aFROMclause. Separating the ZetaSQL parser from the regular ClickHouse parsing separates the concerns into a clean division we can modify them independently.The disadvantage is that is that errors in the generated sql are not mapped directly to the provided sql.
A picture of the suggested approach looks like this:
There are a couple of outstanding questions:
Right now SELECT query is generated when there is an aggregation it looks something like this:
Personally I prefer a CTE structure it's easier to read and to debug as it flows similar to the pipe syntax. From my initial reading it doesn't seem that we should see a performance benefit from using subqueries.