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

@ -505,32 +505,34 @@ namespace
bool parseExtract(IParser::Pos & pos, ASTPtr & node, Expected & expected)
{
ASTPtr expr;
IParser::Pos begin = pos;
IntervalKind interval_kind;
if (!parseIntervalKind(pos, expected, interval_kind))
{
ASTPtr expr_list;
if (!ParserExpressionList(false, false).parse(pos, expr_list, expected))
return false;
auto res = std::make_shared<ASTFunction>();
res->name = "extract";
res->arguments = expr_list;
res->children.push_back(res->arguments);
node = std::move(res);
return true;
if (parseIntervalKind(pos, expected, interval_kind))
{
ASTPtr expr;
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;
}
}
ParserKeyword s_from("FROM");
if (!s_from.ignore(pos, expected))
pos = begin;
ASTPtr expr_list;
if (!ParserExpressionList(false, false).parse(pos, expr_list, expected))
return false;
ParserExpression elem_parser;
if (!elem_parser.parse(pos, expr, expected))
return false;
node = makeASTFunction(interval_kind.toNameOfFunctionExtractTimePart(), expr);
auto res = std::make_shared<ASTFunction>();
res->name = "extract";
res->arguments = expr_list;
res->children.push_back(res->arguments);
node = std::move(res);
return true;
}

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+');