diff --git a/src/Client/QueryFuzzer.cpp b/src/Client/QueryFuzzer.cpp index bb551fcb11eb..24be7491ec76 100644 --- a/src/Client/QueryFuzzer.cpp +++ b/src/Client/QueryFuzzer.cpp @@ -915,18 +915,35 @@ ASTPtr QueryFuzzer::fuzzLiteralUnderExpressionList(ASTPtr child) "toFixedString", std::make_shared(value), std::make_shared(static_cast(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()) + { + std::unordered_set 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) { @@ -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); + } } } diff --git a/src/Client/QueryFuzzer.h b/src/Client/QueryFuzzer.h index cdeba2b76fd8..f5465626d96d 100644 --- a/src/Client/QueryFuzzer.h +++ b/src/Client/QueryFuzzer.h @@ -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);