From ada4384deb5fe0c4dd95459da9ac8a225cf92a51 Mon Sep 17 00:00:00 2001 From: liuneng <1398775315@qq.com> Date: Thu, 21 Mar 2024 10:38:51 +0800 Subject: [PATCH] fix ut failed --- src/Analyzer/Passes/ConvertInToEqualPass.cpp | 16 +++++++++++----- ...est_transform_query_for_external_database.cpp | 6 ++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Analyzer/Passes/ConvertInToEqualPass.cpp b/src/Analyzer/Passes/ConvertInToEqualPass.cpp index fbac09de7aa2..ddd8a8f266f9 100644 --- a/src/Analyzer/Passes/ConvertInToEqualPass.cpp +++ b/src/Analyzer/Passes/ConvertInToEqualPass.cpp @@ -32,7 +32,8 @@ class ConvertInToEqualPassVisitor : public InDepthQueryTreeVisitorWithContextgetValue().getType() == Field::Types::Which::Tuple) + if (constant_node->getValue().getType() == Field::Types::Which::Tuple + || constant_node->getValue().getType() == Field::Types::Which::Array) return ; // x IN null not equivalent to x = null if (constant_node->hasSourceExpression() || constant_node->getValue().isNull()) @@ -51,12 +52,17 @@ class ConvertInToEqualPassVisitor : public InDepthQueryTreeVisitorWithContextresolveAsFunction(resolver); + try + { + equal->resolveAsFunction(resolver); + } + catch (...) + { + // When function resolver fails, we should not replace the function node + return; + } node = equal; } -private: - FunctionOverloadResolverPtr equal_resolver; - FunctionOverloadResolverPtr not_equal_resolver; }; void ConvertInToEqualPass::run(QueryTreeNodePtr & query_tree_node, ContextPtr context) diff --git a/src/Storages/tests/gtest_transform_query_for_external_database.cpp b/src/Storages/tests/gtest_transform_query_for_external_database.cpp index 7e2d393c3d11..6490498d717a 100644 --- a/src/Storages/tests/gtest_transform_query_for_external_database.cpp +++ b/src/Storages/tests/gtest_transform_query_for_external_database.cpp @@ -306,7 +306,8 @@ TEST(TransformQueryForExternalDatabase, Aliases) check(state, 1, {"field"}, "SELECT field AS value, field AS display FROM table WHERE field NOT IN ('') AND display LIKE '%test%'", - R"(SELECT "field" FROM "test"."table" WHERE ("field" NOT IN ('')) AND ("field" LIKE '%test%'))"); + R"(SELECT "field" FROM "test"."table" WHERE ("field" NOT IN ('')) AND ("field" LIKE '%test%'))", + R"(SELECT "field" FROM "test"."table" WHERE ("field" != '') AND ("field" LIKE '%test%'))"); } TEST(TransformQueryForExternalDatabase, ForeignColumnInWhere) @@ -408,5 +409,6 @@ TEST(TransformQueryForExternalDatabase, Analyzer) check(state, 1, {"column", "apply_id", "apply_type", "apply_status", "create_time", "field", "value", "a", "b", "foo"}, "SELECT * FROM table WHERE (column) IN (1)", - R"(SELECT "column", "apply_id", "apply_type", "apply_status", "create_time", "field", "value", "a", "b", "foo" FROM "test"."table" WHERE "column" IN (1))"); + R"(SELECT "column", "apply_id", "apply_type", "apply_status", "create_time", "field", "value", "a", "b", "foo" FROM "test"."table" WHERE "column" IN (1))", + R"(SELECT "column", "apply_id", "apply_type", "apply_status", "create_time", "field", "value", "a", "b", "foo" FROM "test"."table" WHERE "column" = 1)"); }