Skip to content

Commit

Permalink
fix fuzz test
Browse files Browse the repository at this point in the history
  • Loading branch information
liuneng1994 committed Mar 29, 2024
1 parent d5beeba commit 932232a
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Analyzer/Passes/CaseWhenSimplifyPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ class ICaseWhenReplaceAlogrithm
{
chassert(case_node.getFunctionName() == "caseWithExpression");
auto case_args = case_node.getArguments().getNodes();
if (case_args.size() < 3)
{
failed = true;
return;
}
has_else = (case_args.size() - 1) % 2 == 1;
case_column = case_args.at(0);
for (size_t i = 1; i < case_args.size() - (has_else ? 1 : 0); i += 2)
Expand Down Expand Up @@ -405,17 +410,17 @@ class CaseWhenSimplifyPassVisitor : public InDepthQueryTreeVisitorWithContext<Ca
void enterImpl(QueryTreeNodePtr & node)
{
// if parent has isNull or isNotNull function, abandon the optimization
if (parentHasIsNull)
if (in_disabled_function)
return;
static const std::unordered_set<String> is_null_funcs = {"isNull", "isNotNull"};
// null property is hard to handle, so abandon the optimization
static const std::unordered_set<String> disabled_parent_funcs = {"isNull", "isNotNull"};
static const std::unordered_set<String> supported_funcs = {"in", "notIn", "equals", "notEquals"};
auto * func_node = node->as<FunctionNode>();
if (!func_node)
return;
if (is_null_funcs.contains(func_node->getFunctionName()))
if (disabled_parent_funcs.contains(func_node->getFunctionName()))
{
parentHasIsNull = true;
return;
in_disabled_function = true;
}

if (!checkFunctionWithArguments(node, supported_funcs, 2))
Expand Down Expand Up @@ -448,12 +453,12 @@ class CaseWhenSimplifyPassVisitor : public InDepthQueryTreeVisitorWithContext<Ca
CaseWhenNotInReplace replace(*case_node, *value_node, getContext());
new_node = replace.replace();
}
if (new_node)
if (new_node && new_node->getResultType()->equals(*node->getResultType()))
node = new_node;
}

private:
bool parentHasIsNull = false;
bool in_disabled_function = false;
};
}

Expand Down

0 comments on commit 932232a

Please sign in to comment.