Skip to content

Commit

Permalink
fix ut failed
Browse files Browse the repository at this point in the history
  • Loading branch information
liuneng1994 committed Mar 21, 2024
1 parent d2d5f3b commit ada4384
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/Analyzer/Passes/ConvertInToEqualPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class ConvertInToEqualPassVisitor : public InDepthQueryTreeVisitorWithContext<Co
if (!column_node || !constant_node)
return ;
// IN multiple values is not supported
if (constant_node->getValue().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())
Expand All @@ -51,12 +52,17 @@ class ConvertInToEqualPassVisitor : public InDepthQueryTreeVisitorWithContext<Co
{
resolver = createInternalFunctionNotEqualOverloadResolver(decimal_check_overflow);
}
equal->resolveAsFunction(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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)");
}

0 comments on commit ada4384

Please sign in to comment.