Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rui-mo committed Mar 26, 2024
1 parent 9c8cc1b commit d93eca3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
1 change: 0 additions & 1 deletion velox/expression/ConstantExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ void appendSqlLiteral(
case TypeKind::TINYINT:
case TypeKind::SMALLINT:
case TypeKind::BIGINT:
case TypeKind::HUGEINT:
case TypeKind::TIMESTAMP:
case TypeKind::REAL:
case TypeKind::DOUBLE:
Expand Down
32 changes: 23 additions & 9 deletions velox/expression/tests/utils/ArgumentTypeFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,39 @@ void ArgumentTypeFuzzer::determineUnboundedIntegerVariables() {
continue;
}

// When variable name is 'precision' and result type is decimal, input type
// is regarded the same with the result type.
if (variableName == "precision" && returnType_ &&
returnType_->isDecimal()) {
const auto [precision, scale] = getDecimalPrecisionScale(*returnType_);
integerVariablesBindings_["precision"] = precision;
integerVariablesBindings_["scale"] = scale;
} else if (auto pos = variableName.find("precision");
pos != std::string::npos) {
// Handle decimal precisions and scales.
continue;
}

// When decimal function is registered as vector function, the variable name
// contains 'precision' like 'a_precision'.
if (auto pos = variableName.find("precision"); pos != std::string::npos) {
// Generate a random precision, and corresponding scale should not exceed
// the precision.
const auto precision =
boost::random::uniform_int_distribution<uint32_t>(1, 38)(rng_);
integerVariablesBindings_[variableName] = precision;
const auto colName = variableName.substr(0, pos);
// Corresponding scale should not exceed the generated precision.
integerVariablesBindings_[colName + "scale"] =
boost::random::uniform_int_distribution<uint32_t>(0, precision)(rng_);
} else if (auto pos = variableName.find("i"); pos != std::string::npos) {
continue;
}

// When decimal function is registered as simple function, the variable name
// contains 'i' like 'i1'.
if (auto pos = variableName.find("i"); pos != std::string::npos) {
VELOX_USER_CHECK_GE(variableName.size(), 2);
const auto index =
std::stoi(variableName.substr(pos + 1, variableName.size()));
if (index <= kIntegerPairSize) {
// Generate a random precision, and corresponding scale should not
// exceed the precision.
const auto precision =
boost::random::uniform_int_distribution<uint32_t>(1, 38)(rng_);
integerVariablesBindings_[variableName] = precision;
Expand All @@ -76,10 +89,11 @@ void ArgumentTypeFuzzer::determineUnboundedIntegerVariables() {
boost::random::uniform_int_distribution<uint32_t>(
0, precision)(rng_);
}
} else {
integerVariablesBindings_[variableName] =
boost::random::uniform_int_distribution<int32_t>()(rng_);
continue;
}

integerVariablesBindings_[variableName] =
boost::random::uniform_int_distribution<int32_t>()(rng_);
}

// Handle constraints.
Expand All @@ -88,7 +102,7 @@ void ArgumentTypeFuzzer::determineUnboundedIntegerVariables() {
if (constraint == "") {
continue;
}
auto calculation = fmt::format("{}={}", variableName, constraint);
const auto calculation = fmt::format("{}={}", variableName, constraint);
expression::calculation::evaluate(calculation, integerVariablesBindings_);
}
}
Expand Down

0 comments on commit d93eca3

Please sign in to comment.