Skip to content

Commit

Permalink
Backport #53347 to 22.8: Fix incorrect normal projection AST format
Browse files Browse the repository at this point in the history
  • Loading branch information
robot-clickhouse committed Aug 13, 2023
1 parent a156bb0 commit 7cd7d54
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Parsers/ASTProjectionSelectQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ void ASTProjectionSelectQuery::formatImpl(const FormatSettings & s, FormatState

if (orderBy())
{
/// Let's convert the ASTFunction into ASTExpressionList, which generates consistent format
/// Let's convert tuple ASTFunction into ASTExpressionList, which generates consistent format
/// between GROUP BY and ORDER BY projection definition.
s.ostr << (s.hilite ? hilite_keyword : "") << s.nl_or_ws << indent_str << "ORDER BY " << (s.hilite ? hilite_none : "");
ASTPtr order_by;
if (auto * func = orderBy()->as<ASTFunction>())
if (auto * func = orderBy()->as<ASTFunction>(); func && func->name == "tuple")
order_by = func->arguments;
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE default.test\n(\n `uuid` FixedString(16),\n `id` Int32,\n `ns` FixedString(16),\n `dt` DateTime64(6),\n PROJECTION mtlog_proj_source_reference\n (\n SELECT *\n ORDER BY substring(ns, 1, 5)\n )\n)\nENGINE = MergeTree\nORDER BY (id, dt, uuid)\nSETTINGS index_granularity = 8192
17 changes: 17 additions & 0 deletions tests/queries/0_stateless/01710_normal_projection_format.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
DROP TABLE if exists test;

CREATE TABLE test
(
uuid FixedString(16),
id int,
ns FixedString(16),
dt DateTime64(6),
)
ENGINE = MergeTree
ORDER BY (id, dt, uuid);

ALTER TABLE test ADD PROJECTION mtlog_proj_source_reference (SELECT * ORDER BY substring(ns, 1, 5));

SHOW CREATE test;

drop table test;

0 comments on commit 7cd7d54

Please sign in to comment.