From 25088187d409db5e883b66b63b42839d5e7a3c1b Mon Sep 17 00:00:00 2001 From: Maksim Kita Date: Mon, 6 Mar 2023 10:53:55 +0100 Subject: [PATCH] Fixed tests --- src/Analyzer/Passes/QueryAnalysisPass.cpp | 50 +++++++++++++------ src/Planner/PlannerJoinTree.cpp | 1 + ...4_nothing_arguments_in_functions_errors.sh | 4 +- .../02451_order_by_monotonic.reference | 32 ++++++------ .../0_stateless/02451_order_by_monotonic.sh | 20 ++++---- ...2483_cuturlparameter_with_arrays.reference | 1 + 6 files changed, 66 insertions(+), 42 deletions(-) diff --git a/src/Analyzer/Passes/QueryAnalysisPass.cpp b/src/Analyzer/Passes/QueryAnalysisPass.cpp index 8dc0b771cf2..c483a9983b9 100644 --- a/src/Analyzer/Passes/QueryAnalysisPass.cpp +++ b/src/Analyzer/Passes/QueryAnalysisPass.cpp @@ -4608,25 +4608,47 @@ ProjectionNames QueryAnalyzer::resolveFunction(QueryTreeNodePtr & node, Identifi auto if_function_condition = if_function_arguments[0]; resolveExpressionNode(if_function_condition, scope, false /*allow_lambda_expression*/, false /*allow_table_expression*/); - QueryTreeNodePtr constant_if_result_node; auto constant_condition = tryExtractConstantFromConditionNode(if_function_condition); if (constant_condition.has_value() && if_function_arguments.size() == 3) { - if (*constant_condition) - constant_if_result_node = if_function_arguments[1]; - else - constant_if_result_node = if_function_arguments[2]; - } + QueryTreeNodePtr constant_if_result_node; + QueryTreeNodePtr possibly_invalid_argument_node; - if (constant_if_result_node) - { - auto result_projection_names = resolveExpressionNode(constant_if_result_node, - scope, - false /*allow_lambda_expression*/, - false /*allow_table_expression*/); - node = std::move(constant_if_result_node); - return result_projection_names; + if (*constant_condition) + { + possibly_invalid_argument_node = if_function_arguments[2]; + constant_if_result_node = if_function_arguments[1]; + } + else + { + possibly_invalid_argument_node = if_function_arguments[1]; + constant_if_result_node = if_function_arguments[2]; + } + + bool apply_constant_if_optimization = false; + + try + { + resolveExpressionNode(possibly_invalid_argument_node, + scope, + false /*allow_lambda_expression*/, + false /*allow_table_expression*/); + } + catch (...) + { + apply_constant_if_optimization = true; + } + + if (apply_constant_if_optimization) + { + auto result_projection_names = resolveExpressionNode(constant_if_result_node, + scope, + false /*allow_lambda_expression*/, + false /*allow_table_expression*/); + node = std::move(constant_if_result_node); + return result_projection_names; + } } } diff --git a/src/Planner/PlannerJoinTree.cpp b/src/Planner/PlannerJoinTree.cpp index 52a3c926f65..b29c4baf1b0 100644 --- a/src/Planner/PlannerJoinTree.cpp +++ b/src/Planner/PlannerJoinTree.cpp @@ -1193,6 +1193,7 @@ JoinTreeQueryPlan buildJoinTreeQueryPlan(const QueryTreeNodePtr & query_node, if (table_expression == left_table_expression) { query_plans_stack.push_back(std::move(left_table_expression_query_plan)); + left_table_expression = {}; continue; } diff --git a/tests/queries/0_stateless/02294_nothing_arguments_in_functions_errors.sh b/tests/queries/0_stateless/02294_nothing_arguments_in_functions_errors.sh index 8c526cd8da8..931985340c2 100755 --- a/tests/queries/0_stateless/02294_nothing_arguments_in_functions_errors.sh +++ b/tests/queries/0_stateless/02294_nothing_arguments_in_functions_errors.sh @@ -5,6 +5,6 @@ CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) . "$CUR_DIR"/../shell_config.sh $CLICKHOUSE_LOCAL -q "SELECT assumeNotNull(NULL)" 2>&1 | grep -q "ILLEGAL_COLUMN" && echo "OK" || echo "FAIL" -$CLICKHOUSE_LOCAL -q "SELECT assumeNotNull(materialize(NULL)) SETTINGS allow_experimental_analyzer = 1" 2>&1 | grep -q "ILLEGAL_COLUMN" && echo "OK" || echo "FAIL" -$CLICKHOUSE_LOCAL -q "SELECT assumeNotNull(materialize(NULL)) from numbers(10) SETTINGS allow_experimental_analyzer = 1" 2>&1 | grep -q "ILLEGAL_COLUMN" && echo "OK" || echo "FAIL" +$CLICKHOUSE_LOCAL -q "SELECT assumeNotNull(materialize(NULL))" 2>&1 | grep -q "ILLEGAL_TYPE_OF_ARGUMENT" && echo "OK" || echo "FAIL" +$CLICKHOUSE_LOCAL -q "SELECT assumeNotNull(materialize(NULL)) from numbers(10)" 2>&1 | grep -q "ILLEGAL_TYPE_OF_ARGUMENT" && echo "OK" || echo "FAIL" diff --git a/tests/queries/0_stateless/02451_order_by_monotonic.reference b/tests/queries/0_stateless/02451_order_by_monotonic.reference index 37256be556e..f9f0ef38be1 100644 --- a/tests/queries/0_stateless/02451_order_by_monotonic.reference +++ b/tests/queries/0_stateless/02451_order_by_monotonic.reference @@ -4,19 +4,19 @@ 2022-09-09 12:00:00 0x 2022-09-09 12:00:00 1 2022-09-09 12:00:00 1x - Prefix sort description: toStartOfMinute(test.t_order_by_monotonic.t_0) ASC - Result sort description: toStartOfMinute(test.t_order_by_monotonic.t_0) ASC, test.t_order_by_monotonic.c1_1 ASC - Prefix sort description: toStartOfMinute(test.t_order_by_monotonic.t_0) ASC - Result sort description: toStartOfMinute(test.t_order_by_monotonic.t_0) ASC - Prefix sort description: negate(test.t_order_by_monotonic.a_0) ASC - Result sort description: negate(test.t_order_by_monotonic.a_0) ASC - Prefix sort description: negate(test.t_order_by_monotonic.a_0) ASC, negate(test.t_order_by_monotonic.b_1) ASC - Result sort description: negate(test.t_order_by_monotonic.a_0) ASC, negate(test.t_order_by_monotonic.b_1) ASC - Prefix sort description: test.t_order_by_monotonic.a_0 DESC, negate(test.t_order_by_monotonic.b_1) ASC - Result sort description: test.t_order_by_monotonic.a_0 DESC, negate(test.t_order_by_monotonic.b_1) ASC - Prefix sort description: negate(test.t_order_by_monotonic.a_0) ASC, test.t_order_by_monotonic.b_1 DESC - Result sort description: negate(test.t_order_by_monotonic.a_0) ASC, test.t_order_by_monotonic.b_1 DESC - Prefix sort description: negate(test.t_order_by_monotonic.a_0) ASC - Result sort description: negate(test.t_order_by_monotonic.a_0) ASC, test.t_order_by_monotonic.b_1 ASC - Prefix sort description: test.t_order_by_monotonic.a_0 ASC - Result sort description: test.t_order_by_monotonic.a_0 ASC, negate(test.t_order_by_monotonic.b_1) ASC + Prefix sort description: toStartOfMinute(test.t_0) ASC + Result sort description: toStartOfMinute(test.t_0) ASC, test.c1_1 ASC + Prefix sort description: toStartOfMinute(test.t_0) ASC + Result sort description: toStartOfMinute(test.t_0) ASC + Prefix sort description: negate(test.a_0) ASC + Result sort description: negate(test.a_0) ASC + Prefix sort description: negate(test.a_0) ASC, negate(test.b_1) ASC + Result sort description: negate(test.a_0) ASC, negate(test.b_1) ASC + Prefix sort description: test.a_0 DESC, negate(test.b_1) ASC + Result sort description: test.a_0 DESC, negate(test.b_1) ASC + Prefix sort description: negate(test.a_0) ASC, test.b_1 DESC + Result sort description: negate(test.a_0) ASC, test.b_1 DESC + Prefix sort description: negate(test.a_0) ASC + Result sort description: negate(test.a_0) ASC, test.b_1 ASC + Prefix sort description: test.a_0 ASC + Result sort description: test.a_0 ASC, negate(test.b_1) ASC diff --git a/tests/queries/0_stateless/02451_order_by_monotonic.sh b/tests/queries/0_stateless/02451_order_by_monotonic.sh index cc26ba91e1c..4fdc5a9a002 100755 --- a/tests/queries/0_stateless/02451_order_by_monotonic.sh +++ b/tests/queries/0_stateless/02451_order_by_monotonic.sh @@ -17,12 +17,12 @@ $CLICKHOUSE_CLIENT -q "CREATE TABLE t_order_by_monotonic (t DateTime, c1 String) SELECT '2022-09-09 12:00:30', toString(number % 2)|| 'x' FROM numbers(3)" $CLICKHOUSE_CLIENT --optimize_aggregation_in_order=1 -q "SELECT count() FROM - (SELECT toStartOfMinute(t) AS s, c1 FROM t_order_by_monotonic GROUP BY s, c1)" + (SELECT toStartOfMinute(t) AS s, c1 FROM t_order_by_monotonic AS test GROUP BY s, c1)" -$CLICKHOUSE_CLIENT --optimize_read_in_order=1 -q "SELECT toStartOfMinute(t) AS s, c1 FROM t_order_by_monotonic ORDER BY s, c1" +$CLICKHOUSE_CLIENT --optimize_read_in_order=1 -q "SELECT toStartOfMinute(t) AS s, c1 FROM t_order_by_monotonic AS test ORDER BY s, c1" -explain_sort_description "SELECT toStartOfMinute(t) AS s, c1 FROM t_order_by_monotonic ORDER BY s, c1" -explain_sort_description "SELECT toStartOfMinute(t) AS s, c1 FROM t_order_by_monotonic ORDER BY s" +explain_sort_description "SELECT toStartOfMinute(t) AS s, c1 FROM t_order_by_monotonic AS test ORDER BY s, c1" +explain_sort_description "SELECT toStartOfMinute(t) AS s, c1 FROM t_order_by_monotonic AS test ORDER BY s" $CLICKHOUSE_CLIENT -q "DROP TABLE IF EXISTS t_order_by_monotonic" @@ -30,11 +30,11 @@ $CLICKHOUSE_CLIENT -q "CREATE TABLE t_order_by_monotonic (a Int64, b Int64) ENGI $CLICKHOUSE_CLIENT -q "INSERT INTO t_order_by_monotonic VALUES (1, 1) (1, 2), (2, 1) (2, 2)" -explain_sort_description "SELECT * FROM t_order_by_monotonic ORDER BY -a" -explain_sort_description "SELECT * FROM t_order_by_monotonic ORDER BY -a, -b" -explain_sort_description "SELECT * FROM t_order_by_monotonic ORDER BY a DESC, -b" -explain_sort_description "SELECT * FROM t_order_by_monotonic ORDER BY -a, b DESC" -explain_sort_description "SELECT * FROM t_order_by_monotonic ORDER BY -a, b" -explain_sort_description "SELECT * FROM t_order_by_monotonic ORDER BY a, -b" +explain_sort_description "SELECT * FROM t_order_by_monotonic AS test ORDER BY -a" +explain_sort_description "SELECT * FROM t_order_by_monotonic AS test ORDER BY -a, -b" +explain_sort_description "SELECT * FROM t_order_by_monotonic AS test ORDER BY a DESC, -b" +explain_sort_description "SELECT * FROM t_order_by_monotonic AS test ORDER BY -a, b DESC" +explain_sort_description "SELECT * FROM t_order_by_monotonic AS test ORDER BY -a, b" +explain_sort_description "SELECT * FROM t_order_by_monotonic AS test ORDER BY a, -b" $CLICKHOUSE_CLIENT -q "DROP TABLE IF EXISTS t_order_by_monotonic" diff --git a/tests/queries/0_stateless/02483_cuturlparameter_with_arrays.reference b/tests/queries/0_stateless/02483_cuturlparameter_with_arrays.reference index fa7f9ee7a2c..348408a15cc 100644 --- a/tests/queries/0_stateless/02483_cuturlparameter_with_arrays.reference +++ b/tests/queries/0_stateless/02483_cuturlparameter_with_arrays.reference @@ -1,4 +1,5 @@ -- { echoOn } + SELECT cutURLParameter('http://bigmir.net/?a=b&c=d', []), cutURLParameter('http://bigmir.net/?a=b&c=d', ['a']),