From bf3a3ad607bf1059fc1839fc1ff5c2806dac1b86 Mon Sep 17 00:00:00 2001 From: Yakov Olkhovskiy Date: Tue, 8 Oct 2024 02:27:36 +0000 Subject: [PATCH 1/2] fix ephemeral comment --- src/Parsers/ParserCreateQuery.h | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Parsers/ParserCreateQuery.h b/src/Parsers/ParserCreateQuery.h index 82da2e7ea0b..a58e190ecd9 100644 --- a/src/Parsers/ParserCreateQuery.h +++ b/src/Parsers/ParserCreateQuery.h @@ -237,6 +237,7 @@ bool IParserColumnDeclaration::parseImpl(Pos & pos, ASTPtr & node, E null_modifier.emplace(true); } + bool is_comment = false; /// Collate is also allowed after NULL/NOT NULL if (!collation_expression && s_collate.ignore(pos, expected) && !collation_parser.parse(pos, collation_expression, expected)) @@ -254,7 +255,9 @@ bool IParserColumnDeclaration::parseImpl(Pos & pos, ASTPtr & node, E else if (s_ephemeral.ignore(pos, expected)) { default_specifier = s_ephemeral.getName(); - if (!expr_parser.parse(pos, default_expression, expected) && type) + if (s_comment.ignore(pos, expected)) + is_comment = true; + if ((is_comment || !expr_parser.parse(pos, default_expression, expected)) && type) { ephemeral_default = true; @@ -289,19 +292,22 @@ bool IParserColumnDeclaration::parseImpl(Pos & pos, ASTPtr & node, E if (require_type && !type && !default_expression) return false; /// reject column name without type - if ((type || default_expression) && allow_null_modifiers && !null_modifier.has_value()) + if (!is_comment) { - if (s_not.ignore(pos, expected)) + if ((type || default_expression) && allow_null_modifiers && !null_modifier.has_value()) { - if (!s_null.ignore(pos, expected)) - return false; - null_modifier.emplace(false); + if (s_not.ignore(pos, expected)) + { + if (!s_null.ignore(pos, expected)) + return false; + null_modifier.emplace(false); + } + else if (s_null.ignore(pos, expected)) + null_modifier.emplace(true); } - else if (s_null.ignore(pos, expected)) - null_modifier.emplace(true); } - if (s_comment.ignore(pos, expected)) + if (is_comment || s_comment.ignore(pos, expected)) { /// should be followed by a string literal if (!string_literal_parser.parse(pos, comment_expression, expected)) From 3827d90bb0e896320d8281073a266a75fa6773ce Mon Sep 17 00:00:00 2001 From: Yakov Olkhovskiy Date: Tue, 8 Oct 2024 02:37:41 +0000 Subject: [PATCH 2/2] add test --- .../0_stateless/03250_ephemeral_comment.reference | 0 tests/queries/0_stateless/03250_ephemeral_comment.sql | 11 +++++++++++ 2 files changed, 11 insertions(+) create mode 100644 tests/queries/0_stateless/03250_ephemeral_comment.reference create mode 100644 tests/queries/0_stateless/03250_ephemeral_comment.sql diff --git a/tests/queries/0_stateless/03250_ephemeral_comment.reference b/tests/queries/0_stateless/03250_ephemeral_comment.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/03250_ephemeral_comment.sql b/tests/queries/0_stateless/03250_ephemeral_comment.sql new file mode 100644 index 00000000000..906417b9c29 --- /dev/null +++ b/tests/queries/0_stateless/03250_ephemeral_comment.sql @@ -0,0 +1,11 @@ +drop table if exists test; +CREATE TABLE test ( + `start_s` UInt32 EPHEMERAL COMMENT 'start UNIX time' , + `start_us` UInt16 EPHEMERAL COMMENT 'start microseconds', + `finish_s` UInt32 EPHEMERAL COMMENT 'finish UNIX time', + `finish_us` UInt16 EPHEMERAL COMMENT 'finish microseconds', + `captured` DateTime MATERIALIZED fromUnixTimestamp(start_s), + `duration` Decimal32(6) MATERIALIZED finish_s - start_s + (finish_us - start_us)/1000000 +) +ENGINE Null; +drop table if exists test;