From e6352234c31a1eebea36d461cf29675d8d1a1b63 Mon Sep 17 00:00:00 2001 From: Aleksandr Musorin Date: Tue, 23 Jan 2024 14:43:30 +0100 Subject: [PATCH 1/2] Added parsing trailing symbols for type expressions ```sql SELECT (1, 'foo')::Tuple(a Int, b String,); SELECT (1, 'foo')::Tuple(Int, String,); SELECT (1, (2,'foo'))::Tuple(Int, Tuple(Int, String,),); ```` fix --- src/Parsers/ParserDataType.cpp | 15 +++++++++++++++ .../0_stateless/02676_trailing_commas.reference | 3 +++ .../queries/0_stateless/02676_trailing_commas.sql | 4 ++++ 3 files changed, 22 insertions(+) diff --git a/src/Parsers/ParserDataType.cpp b/src/Parsers/ParserDataType.cpp index 3e2a6facac6..99c0b4b29ac 100644 --- a/src/Parsers/ParserDataType.cpp +++ b/src/Parsers/ParserDataType.cpp @@ -116,6 +116,18 @@ bool ParserDataType::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) if (!type_name_suffix.empty()) type_name = type_name_upper + " " + type_name_suffix; + /// skip trailing comma in types, e.g. Tuple(Int, String,) + if (pos->type == TokenType::Comma) + { + Expected test_expected; + auto test_pos = pos; + ++test_pos; + if (ParserToken(TokenType::ClosingRoundBracket).ignore(test_pos, test_expected)) + { // the end of the type definition was reached, there was a trailing comma + ++pos; + } + } + auto function_node = std::make_shared(); function_node->name = type_name; function_node->no_empty_args = true; @@ -133,6 +145,9 @@ bool ParserDataType::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) if (!args_parser.parse(pos, expr_list_args, expected)) return false; + if (pos->type == TokenType::Comma) + // ignore trailing comma inside Nested structures like Tuple(Int, Tuple(Int, String),) + ++pos; if (pos->type != TokenType::ClosingRoundBracket) return false; ++pos; diff --git a/tests/queries/0_stateless/02676_trailing_commas.reference b/tests/queries/0_stateless/02676_trailing_commas.reference index 76d173ca23e..cfb2ccd6a0f 100644 --- a/tests/queries/0_stateless/02676_trailing_commas.reference +++ b/tests/queries/0_stateless/02676_trailing_commas.reference @@ -3,3 +3,6 @@ 1 1 2 0 1 +(1,'foo') +(1,'foo') +(1,(2,'foo')) diff --git a/tests/queries/0_stateless/02676_trailing_commas.sql b/tests/queries/0_stateless/02676_trailing_commas.sql index 048405c4d20..7fb64bb57a3 100644 --- a/tests/queries/0_stateless/02676_trailing_commas.sql +++ b/tests/queries/0_stateless/02676_trailing_commas.sql @@ -3,3 +3,7 @@ SELECT 1, FROM numbers(1); WITH 1 as a SELECT a, FROM numbers(1); WITH 1 as from SELECT from, from + from, from in [0], FROM numbers(1); SELECT n, FROM (SELECT 1 AS n); +SELECT (1, 'foo')::Tuple(a Int, b String,); +SELECT (1, 'foo')::Tuple(a Int, b String,,); -- { clientError SYNTAX_ERROR } +SELECT (1, 'foo')::Tuple(Int, String,); +SELECT (1, (2,'foo'))::Tuple(Int, Tuple(Int, String,),); From 9f2093df75f0b0960e1d1a0fa80305f55d00a32e Mon Sep 17 00:00:00 2001 From: Yarik Briukhovetskyi <114298166+yariks5s@users.noreply.github.com> Date: Mon, 29 Jan 2024 12:54:29 +0100 Subject: [PATCH 2/2] Restart CI --- src/Parsers/ParserDataType.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Parsers/ParserDataType.cpp b/src/Parsers/ParserDataType.cpp index 99c0b4b29ac..b75f17dca72 100644 --- a/src/Parsers/ParserDataType.cpp +++ b/src/Parsers/ParserDataType.cpp @@ -123,7 +123,7 @@ bool ParserDataType::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) auto test_pos = pos; ++test_pos; if (ParserToken(TokenType::ClosingRoundBracket).ignore(test_pos, test_expected)) - { // the end of the type definition was reached, there was a trailing comma + { // the end of the type definition was reached and there was a trailing comma ++pos; } }