Merge pull request #70458 from ClickHouse/fix-ephemeral-comment

Fix ephemeral column comment
This commit is contained in:
Yakov Olkhovskiy 2024-11-21 05:10:11 +00:00 committed by GitHub
commit e0f8b8d351
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 9 deletions

View File

@ -237,6 +237,7 @@ bool IParserColumnDeclaration<NameParser>::parseImpl(Pos & pos, ASTPtr & node, E
null_modifier.emplace(true); null_modifier.emplace(true);
} }
bool is_comment = false;
/// Collate is also allowed after NULL/NOT NULL /// Collate is also allowed after NULL/NOT NULL
if (!collation_expression && s_collate.ignore(pos, expected) if (!collation_expression && s_collate.ignore(pos, expected)
&& !collation_parser.parse(pos, collation_expression, expected)) && !collation_parser.parse(pos, collation_expression, expected))
@ -254,7 +255,9 @@ bool IParserColumnDeclaration<NameParser>::parseImpl(Pos & pos, ASTPtr & node, E
else if (s_ephemeral.ignore(pos, expected)) else if (s_ephemeral.ignore(pos, expected))
{ {
default_specifier = s_ephemeral.getName(); 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; ephemeral_default = true;
@ -289,6 +292,8 @@ bool IParserColumnDeclaration<NameParser>::parseImpl(Pos & pos, ASTPtr & node, E
if (require_type && !type && !default_expression) if (require_type && !type && !default_expression)
return false; /// reject column name without type return false; /// reject column name without type
if (!is_comment)
{
if ((type || default_expression) && allow_null_modifiers && !null_modifier.has_value()) if ((type || default_expression) && allow_null_modifiers && !null_modifier.has_value())
{ {
if (s_not.ignore(pos, expected)) if (s_not.ignore(pos, expected))
@ -300,8 +305,9 @@ bool IParserColumnDeclaration<NameParser>::parseImpl(Pos & pos, ASTPtr & node, E
else if (s_null.ignore(pos, expected)) else if (s_null.ignore(pos, expected))
null_modifier.emplace(true); 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 /// should be followed by a string literal
if (!string_literal_parser.parse(pos, comment_expression, expected)) if (!string_literal_parser.parse(pos, comment_expression, expected))

View File

@ -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;