mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 00:30:49 +00:00
Merge pull request #59119 from AVMusorin/trailing-comma-tuples
Allow trailing commas in types with several items
This commit is contained in:
commit
5816424c2b
@ -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;
|
||||
|
@ -3,3 +3,6 @@
|
||||
1
|
||||
1 2 0
|
||||
1
|
||||
(1,'foo')
|
||||
(1,'foo')
|
||||
(1,(2,'foo'))
|
||||
|
@ -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,),);
|
||||
|
Loading…
Reference in New Issue
Block a user