From 91b62c56d2d9d8c6e855c7b9e45dd9a619db8e41 Mon Sep 17 00:00:00 2001 From: Han Fei Date: Fri, 15 Nov 2024 18:54:01 +0100 Subject: [PATCH] fix bug when column description has settings, ttl and statistics --- src/Storages/ColumnsDescription.cpp | 24 +++++++++---------- ..._fix_column_modifier_write_order.reference | 0 .../03270_fix_column_modifier_write_order.sql | 5 ++++ 3 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 tests/queries/0_stateless/03270_fix_column_modifier_write_order.reference create mode 100644 tests/queries/0_stateless/03270_fix_column_modifier_write_order.sql diff --git a/src/Storages/ColumnsDescription.cpp b/src/Storages/ColumnsDescription.cpp index b96c620592d..18514f0b58a 100644 --- a/src/Storages/ColumnsDescription.cpp +++ b/src/Storages/ColumnsDescription.cpp @@ -157,18 +157,6 @@ void ColumnDescription::writeText(WriteBuffer & buf, IAST::FormatState & state, writeEscapedString(formatASTStateAware(*codec, state), buf); } - if (!settings.empty()) - { - writeChar('\t', buf); - DB::writeText("SETTINGS ", buf); - DB::writeText("(", buf); - ASTSetQuery ast; - ast.is_standalone = false; - ast.changes = settings; - writeEscapedString(formatASTStateAware(ast, state), buf); - DB::writeText(")", buf); - } - if (!statistics.empty()) { writeChar('\t', buf); @@ -182,6 +170,18 @@ void ColumnDescription::writeText(WriteBuffer & buf, IAST::FormatState & state, writeEscapedString(formatASTStateAware(*ttl, state), buf); } + if (!settings.empty()) + { + writeChar('\t', buf); + DB::writeText("SETTINGS ", buf); + DB::writeText("(", buf); + ASTSetQuery ast; + ast.is_standalone = false; + ast.changes = settings; + writeEscapedString(formatASTStateAware(ast, state), buf); + DB::writeText(")", buf); + } + writeChar('\n', buf); } diff --git a/tests/queries/0_stateless/03270_fix_column_modifier_write_order.reference b/tests/queries/0_stateless/03270_fix_column_modifier_write_order.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/03270_fix_column_modifier_write_order.sql b/tests/queries/0_stateless/03270_fix_column_modifier_write_order.sql new file mode 100644 index 00000000000..cf3683df85d --- /dev/null +++ b/tests/queries/0_stateless/03270_fix_column_modifier_write_order.sql @@ -0,0 +1,5 @@ +drop table if exists t1; +SET allow_experimental_statistics = 1; +create table t1 (d Datetime, c0 Int TTL d + INTERVAL 1 MONTH SETTINGS (max_compress_block_size = 1), c2 Int STATISTICS(Uniq) SETTINGS (max_compress_block_size = 1)) Engine = MergeTree() ORDER BY (); +insert into t1 values ('2024-11-15 18:30:00', 25, 20); +