From d93eca32a92280ac153cfa34003f86a5df06b8a6 Mon Sep 17 00:00:00 2001 From: rui-mo Date: Tue, 26 Mar 2024 16:07:47 +0800 Subject: [PATCH] Fix --- velox/expression/ConstantExpr.cpp | 1 - .../tests/utils/ArgumentTypeFuzzer.cpp | 32 +++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/velox/expression/ConstantExpr.cpp b/velox/expression/ConstantExpr.cpp index 381d93741e45e..28c43048be338 100644 --- a/velox/expression/ConstantExpr.cpp +++ b/velox/expression/ConstantExpr.cpp @@ -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: diff --git a/velox/expression/tests/utils/ArgumentTypeFuzzer.cpp b/velox/expression/tests/utils/ArgumentTypeFuzzer.cpp index 93ed98cac6666..838c5ab50f760 100644 --- a/velox/expression/tests/utils/ArgumentTypeFuzzer.cpp +++ b/velox/expression/tests/utils/ArgumentTypeFuzzer.cpp @@ -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(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(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(1, 38)(rng_); integerVariablesBindings_[variableName] = precision; @@ -76,10 +89,11 @@ void ArgumentTypeFuzzer::determineUnboundedIntegerVariables() { boost::random::uniform_int_distribution( 0, precision)(rng_); } - } else { - integerVariablesBindings_[variableName] = - boost::random::uniform_int_distribution()(rng_); + continue; } + + integerVariablesBindings_[variableName] = + boost::random::uniform_int_distribution()(rng_); } // Handle constraints. @@ -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_); } }