From 01e09ba44e05098ac00f3226de9f529f07a6e730 Mon Sep 17 00:00:00 2001 From: Maksim Kita Date: Thu, 21 Apr 2022 12:29:35 +0200 Subject: [PATCH] Fixed tests --- src/Parsers/ExpressionElementParsers.cpp | 22 +++++++++++++++---- ...ecial_operator_parse_alias_check.reference | 4 ++++ ...267_special_operator_parse_alias_check.sql | 4 ++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Parsers/ExpressionElementParsers.cpp b/src/Parsers/ExpressionElementParsers.cpp index 122d9c545aa..5c28fd8190b 100644 --- a/src/Parsers/ExpressionElementParsers.cpp +++ b/src/Parsers/ExpressionElementParsers.cpp @@ -593,7 +593,6 @@ namespace /// First try to match with date extract operator EXTRACT(part FROM date) /// Then with function extract(haystack, pattern) - IParser::Pos begin = pos; IntervalKind interval_kind; if (parseIntervalKind(pos, expected, interval_kind)) @@ -608,9 +607,9 @@ namespace node = makeASTFunction(interval_kind.toNameOfFunctionExtractTimePart(), expr); return true; } - } - pos = begin; + return false; + } ASTPtr expr_list; if (!ParserExpressionList(true /*allow_alias_without_as_keyword*/).parse(pos, expr_list, expected)) @@ -758,7 +757,22 @@ namespace if (!ParserExpressionWithOptionalAlias(true /*allow_alias_without_as_keyword*/).parse(pos, right_node, expected)) return false; - node = makeASTFunction("dateDiff", std::make_shared(interval_kind.toDateDiffUnit()), left_node, right_node); + ASTPtr timezone_node; + + if (pos->type == TokenType::Comma) + { + /// Optional timezone + ++pos; + + if (!ParserExpressionWithOptionalAlias(true /*allow_alias_without_as_keyword*/).parse(pos, timezone_node, expected)) + return false; + } + + auto interval_literal = std::make_shared(interval_kind.toDateDiffUnit()); + if (timezone_node) + node = makeASTFunction("dateDiff", std::move(interval_literal), std::move(left_node), std::move(right_node), std::move(timezone_node)); + else + node = makeASTFunction("dateDiff", std::move(interval_literal), std::move(left_node), std::move(right_node)); return true; } diff --git a/tests/queries/0_stateless/02267_special_operator_parse_alias_check.reference b/tests/queries/0_stateless/02267_special_operator_parse_alias_check.reference index bf33e71e45e..401d4d493a8 100644 --- a/tests/queries/0_stateless/02267_special_operator_parse_alias_check.reference +++ b/tests/queries/0_stateless/02267_special_operator_parse_alias_check.reference @@ -54,3 +54,7 @@ bc a abca 1 2019-05-05 2019-05-06 1 2019-05-05 2019-05-06 1 2019-05-05 2019-05-06 +1 2019-05-05 2019-05-06 +1 2019-05-05 2019-05-06 +1 2019-05-05 2019-05-06 +1 2019-05-05 2019-05-06 diff --git a/tests/queries/0_stateless/02267_special_operator_parse_alias_check.sql b/tests/queries/0_stateless/02267_special_operator_parse_alias_check.sql index 6f95131315f..423bb619b00 100644 --- a/tests/queries/0_stateless/02267_special_operator_parse_alias_check.sql +++ b/tests/queries/0_stateless/02267_special_operator_parse_alias_check.sql @@ -110,8 +110,12 @@ SELECT dateSub(DAY, 1 arg_1, toDate('2019-05-05') arg_2), arg_1, arg_2; SELECT dateDiff(DAY, toDate('2019-05-05') AS arg_1, toDate('2019-05-06') AS arg_2), arg_1, arg_2; SELECT dateDiff(DAY, toDate('2019-05-05') arg_1, toDate('2019-05-06') arg_2), arg_1, arg_2; +SELECT dateDiff(DAY, toDate('2019-05-05') AS arg_1, toDate('2019-05-06') AS arg_2, 'UTC'), arg_1, arg_2; +SELECT dateDiff(DAY, toDate('2019-05-05') arg_1, toDate('2019-05-06') arg_2, 'UTC'), arg_1, arg_2; -- dateDiff('unit', startdate, enddate, [timezone]) SELECT dateDiff('DAY', toDate('2019-05-05') AS arg_1, toDate('2019-05-06') AS arg_2), arg_1, arg_2; SELECT dateDiff('DAY', toDate('2019-05-05') arg_1, toDate('2019-05-06') arg_2), arg_1, arg_2; +SELECT dateDiff('DAY', toDate('2019-05-05') AS arg_1, toDate('2019-05-06') AS arg_2, 'UTC'), arg_1, arg_2; +SELECT dateDiff('DAY', toDate('2019-05-05') arg_1, toDate('2019-05-06') arg_2, 'UTC'), arg_1, arg_2;