Skip to content

Commit

Permalink
fix error for in Null
Browse files Browse the repository at this point in the history
  • Loading branch information
liuneng1994 committed Mar 20, 2024
1 parent 862abf2 commit 45bbef6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/Analyzer/Passes/ConvertInToEqualPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ class ConvertInToEqualPassVisitor : public InDepthQueryTreeVisitorWithContext<Co
auto * constant_node = args[1]->as<ConstantNode>();
if (!column_node || !constant_node)
return ;
// IN multiple values is not supported
if (constant_node->getValue().getType() == Field::Types::Which::Tuple)
return;

return ;
// x IN null not equivalent to x = null
if (constant_node->hasSourceExpression() || constant_node->getValue().isNull())
return ;
auto equal_resolver = createInternalFunctionEqualOverloadResolver();
auto equal = std::make_shared<FunctionNode>("equals");
QueryTreeNodes arguments{column_node->clone(), constant_node->clone()};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
a 1
-------------------
0
0
0
0
0
-------------------
QUERY id: 0
PROJECTION COLUMNS
x String
Expand Down
4 changes: 3 additions & 1 deletion tests/queries/0_stateless/03013_optimize_in_to_equal.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ INSERT INTO test VALUES ('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5);

select * from test where x in ('a') SETTINGS allow_experimental_analyzer = 1;
select '-------------------';
select x in Null from test;
select '-------------------';
explain query tree select * from test where x in ('a') SETTINGS allow_experimental_analyzer = 1;
select '-------------------';
explain query tree select * from test where x in ('a','b') SETTINGS allow_experimental_analyzer = 1;
explain query tree select * from test where x in ('a','b') SETTINGS allow_experimental_analyzer = 1;

0 comments on commit 45bbef6

Please sign in to comment.