Skip to content

Commit

Permalink
try
Browse files Browse the repository at this point in the history
  • Loading branch information
rui-mo committed Mar 19, 2024
1 parent ec25e51 commit 65552c4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
25 changes: 21 additions & 4 deletions velox/expression/tests/ExpressionFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1106,11 +1106,28 @@ std::vector<core::TypedExprPtr> ExpressionFuzzer::getArgsForCallable(

core::TypedExprPtr ExpressionFuzzer::getCallExprFromCallable(
const CallableSignature& callable,
const TypePtr& type) {
const TypePtr& type,
const exec::FunctionSignature* signature) {
auto args = getArgsForCallable(callable);
std::unordered_map<std::string, int> integerVariablesBindings;
for (column_index_t i = 0; i < args.size(); ++i) {
const auto& argType = args[i]->type();
if (argType->isDecimal()) {
const auto [p, s] = getDecimalPrecisionScale(*argType);
char column = 'a' + i;
integerVariablesBindings[column + "_precision"] = p;
integerVariablesBindings[column + "_scale"] = s;
}
}

// Generate a CallTypedExpr with type because callable.returnType may not have
// the required field names.
return std::make_shared<core::CallTypedExpr>(type, args, callable.name);
auto outputType = type;
if (type->isDecimal() && integerVariablesBindings.size() > 0 && signature) {
ArgumentTypeFuzzer fuzzer{*signature, rng_, integerVariablesBindings};
outputType = fuzzer.fuzzReturnType();
}
return std::make_shared<core::CallTypedExpr>(outputType, args, callable.name);
}

const CallableSignature* ExpressionFuzzer::chooseRandomConcreteSignature(
Expand Down Expand Up @@ -1192,7 +1209,7 @@ core::TypedExprPtr ExpressionFuzzer::generateExpressionFromConcreteSignatures(
}

markSelected(chosen->name);
return getCallExprFromCallable(*chosen, returnType);
return getCallExprFromCallable(*chosen, returnType, nullptr);
}

const SignatureTemplate* ExpressionFuzzer::chooseRandomSignatureTemplate(
Expand Down Expand Up @@ -1301,7 +1318,7 @@ core::TypedExprPtr ExpressionFuzzer::generateExpressionFromSignatureTemplate(
.constantArgs = constantArguments};

markSelected(chosen->name);
return getCallExprFromCallable(callable, outputType);
return getCallExprFromCallable(callable, outputType, chosen->signature);
}

core::TypedExprPtr ExpressionFuzzer::generateCastExpression(
Expand Down
3 changes: 2 additions & 1 deletion velox/expression/tests/ExpressionFuzzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ class ExpressionFuzzer {

core::TypedExprPtr getCallExprFromCallable(
const CallableSignature& callable,
const TypePtr& type);
const TypePtr& type,
const exec::FunctionSignature* signature = nullptr);

/// Return a random signature mapped to functionName in
/// expressionToSignature_ whose return type can match returnType. Return
Expand Down
7 changes: 7 additions & 0 deletions velox/expression/tests/utils/ArgumentTypeFuzzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ class ArgumentTypeFuzzer {
std::mt19937& rng)
: ArgumentTypeFuzzer(signature, nullptr, rng) {}

ArgumentTypeFuzzer(
const exec::FunctionSignature& signature,
std::mt19937& rng,
std::unordered_map<std::string, int> integerVariablesBindings)
: ArgumentTypeFuzzer(signature, nullptr, rng),
integerVariablesBindings_(integerVariablesBindings) {}

ArgumentTypeFuzzer(
const exec::FunctionSignature& signature,
const TypePtr& returnType,
Expand Down

0 comments on commit 65552c4

Please sign in to comment.