Skip to content

Commit

Permalink
Add reverse step
Browse files Browse the repository at this point in the history
  • Loading branch information
Algunenano committed Feb 2, 2024
1 parent 00096e5 commit 7be91e6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/Client/QueryFuzzer.cpp
Expand Up @@ -915,18 +915,35 @@ ASTPtr QueryFuzzer::fuzzLiteralUnderExpressionList(ASTPtr child)
"toFixedString", std::make_shared<ASTLiteral>(value), std::make_shared<ASTLiteral>(static_cast<UInt64>(value.size())));
}

if (fuzz_rand() % 11 == 0)
if (fuzz_rand() % 7 == 0)
child = makeASTFunction("toNullable", child);

if (fuzz_rand() % 11 == 0)
if (fuzz_rand() % 7 == 0)
child = makeASTFunction("toLowCardinality", child);

if (fuzz_rand() % 11 == 0)
if (fuzz_rand() % 7 == 0)
child = makeASTFunction("materialize", child);

return child;
}

/// Tries to remove the functions added in fuzzLiteralUnderExpressionList
/// Note that it removes them even if the child is not a literal
ASTPtr QueryFuzzer::reverseLiteralFuzzing(ASTPtr child)
{
if (auto * function = child.get()->as<ASTFunction>())
{
std::unordered_set<String> can_be_reverted{"toNullable", "toLowCardinality", "materialize"};
if (can_be_reverted.contains(function->name) && function->children.size() == 1)
{
if (fuzz_rand() % 7 == 0)
return function->children[0];
}
}

return nullptr;
}


void QueryFuzzer::fuzzExpressionList(ASTExpressionList & expr_list)
{
Expand All @@ -938,7 +955,13 @@ void QueryFuzzer::fuzzExpressionList(ASTExpressionList & expr_list)
child = fuzzLiteralUnderExpressionList(child);
}
else
fuzz(child);
{
auto new_child = reverseLiteralFuzzing(child);
if (new_child)
child = new_child;
else
fuzz(child);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/Client/QueryFuzzer.h
Expand Up @@ -96,6 +96,7 @@ struct QueryFuzzer
void fuzzColumnDeclaration(ASTColumnDeclaration & column);
void fuzzTableName(ASTTableExpression & table);
ASTPtr fuzzLiteralUnderExpressionList(ASTPtr child);
ASTPtr reverseLiteralFuzzing(ASTPtr child);
void fuzzExpressionList(ASTExpressionList & expr_list);
void fuzz(ASTs & asts);
void fuzz(ASTPtr & ast);
Expand Down

0 comments on commit 7be91e6

Please sign in to comment.