Merge pull request #59119 from AVMusorin/trailing-comma-tuples

Allow trailing commas in types with several items
This commit is contained in:
Yarik Briukhovetskyi 2024-01-30 16:31:54 +01:00 committed by GitHub
commit 5816424c2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 0 deletions

View File

@ -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 and there was a trailing comma
++pos;
}
}
auto function_node = std::make_shared<ASTFunction>();
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;

View File

@ -3,3 +3,6 @@
1
1 2 0
1
(1,'foo')
(1,'foo')
(1,(2,'foo'))

View File

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