Merge pull request #35799 from evillique/extract-parser-fix

Fix extract function parser
This commit is contained in:
Kseniia Sumarokova 2022-04-01 10:59:39 +02:00 committed by GitHub
commit cafff71d2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 20 deletions

View File

@ -504,12 +504,26 @@ namespace
}
bool parseExtract(IParser::Pos & pos, ASTPtr & node, Expected & expected)
{
IParser::Pos begin = pos;
IntervalKind interval_kind;
if (parseIntervalKind(pos, expected, interval_kind))
{
ASTPtr expr;
IntervalKind interval_kind;
if (!parseIntervalKind(pos, expected, interval_kind))
ParserKeyword s_from("FROM");
ParserExpression elem_parser;
if (s_from.ignore(pos, expected) && elem_parser.parse(pos, expr, expected))
{
node = makeASTFunction(interval_kind.toNameOfFunctionExtractTimePart(), expr);
return true;
}
}
pos = begin;
ASTPtr expr_list;
if (!ParserExpressionList(false, false).parse(pos, expr_list, expected))
return false;
@ -522,18 +536,6 @@ namespace
return true;
}
ParserKeyword s_from("FROM");
if (!s_from.ignore(pos, expected))
return false;
ParserExpression elem_parser;
if (!elem_parser.parse(pos, expr, expected))
return false;
node = makeASTFunction(interval_kind.toNameOfFunctionExtractTimePart(), expr);
return true;
}
bool parsePosition(IParser::Pos & pos, ASTPtr & node, Expected & expected)
{
ASTPtr expr_list_node;

View File

@ -0,0 +1,3 @@
1
2
3

View File

@ -0,0 +1,3 @@
WITH 'number: 1' as year SELECT extract(year, '\\d+');
WITH 'number: 2' as mm SELECT extract(mm, '\\d+');
WITH 'number: 3' as s SELECT extract(s, '\\d+');