From b023f9ae68b0cec5e83127efbdc4aab0775def82 Mon Sep 17 00:00:00 2001 From: rui-mo Date: Thu, 28 Mar 2024 10:30:53 +0800 Subject: [PATCH] Fix --- velox/expression/ConstantExpr.cpp | 1 + velox/expression/tests/ExprTest.cpp | 11 +++++++++++ velox/expression/tests/ExpressionFuzzer.cpp | 17 +++++++++-------- .../tests/utils/ArgumentTypeFuzzer.cpp | 10 ---------- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/velox/expression/ConstantExpr.cpp b/velox/expression/ConstantExpr.cpp index 28c43048be338..381d93741e45e 100644 --- a/velox/expression/ConstantExpr.cpp +++ b/velox/expression/ConstantExpr.cpp @@ -162,6 +162,7 @@ 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/ExprTest.cpp b/velox/expression/tests/ExprTest.cpp index 38ad6ef6196f5..232fceb0dedd2 100644 --- a/velox/expression/tests/ExprTest.cpp +++ b/velox/expression/tests/ExprTest.cpp @@ -2615,6 +2615,17 @@ TEST_P(ParameterizedExprTest, constantToSql) { ASSERT_EQ(toSql(2134456LL), "'2134456'::BIGINT"); ASSERT_EQ(toSql(variant::null(TypeKind::BIGINT)), "NULL::BIGINT"); + ASSERT_EQ(toSql(2134456LL, DECIMAL(18, 2)), "'21344.56'::DECIMAL(18, 2)"); + ASSERT_EQ( + toSql(variant::null(TypeKind::BIGINT), DECIMAL(18, 2)), + "NULL::DECIMAL(18, 2)"); + ASSERT_EQ( + toSql((int128_t)1'000'000'000'000'000'000, DECIMAL(38, 2)), + "'10000000000000000.00'::DECIMAL(38, 2)"); + ASSERT_EQ( + toSql(variant::null(TypeKind::HUGEINT), DECIMAL(38, 2)), + "NULL::DECIMAL(38, 2)"); + ASSERT_EQ(toSql(18'506, DATE()), "'2020-09-01'::DATE"); ASSERT_EQ(toSql(variant::null(TypeKind::INTEGER), DATE()), "NULL::DATE"); diff --git a/velox/expression/tests/ExpressionFuzzer.cpp b/velox/expression/tests/ExpressionFuzzer.cpp index 94306c0c76d86..b5dc1518338a4 100644 --- a/velox/expression/tests/ExpressionFuzzer.cpp +++ b/velox/expression/tests/ExpressionFuzzer.cpp @@ -447,18 +447,19 @@ bool isSupportedSignature( const exec::FunctionSignature& signature, bool enableComplexType, bool enableDecimalType) { - // When enableDecimalType is disabled, not supporting decimal functions. - const bool useDecimal = - (useTypeName(signature, "long_decimal") || - useTypeName(signature, "short_decimal") || - useTypeName(signature, "decimal")); - // Not supporting lambda functions, or functions using timestamp with time - // zone types. + // When enableComplexType is disabled, not supporting complex functions. + const bool useComplexType = + (useTypeName(signature, "array") || useTypeName(signature, "map") || + useTypeName(signature, "row")); + // When enableDecimalType is disabled, not supporting decimal functions. Not + // supporting lambda functions, or functions using timestamp with time zone + // types. return !( useTypeName(signature, "opaque") || useTypeName(signature, "timestamp with time zone") || useTypeName(signature, "interval day to second") || - (!enableDecimalType && useDecimal) || + (!enableDecimalType && useTypeName(signature, "decimal")) || + (!enableComplexType && useComplexType) || (enableComplexType && useTypeName(signature, "unknown"))); } diff --git a/velox/expression/tests/utils/ArgumentTypeFuzzer.cpp b/velox/expression/tests/utils/ArgumentTypeFuzzer.cpp index 838c5ab50f760..4eb9ce3449059 100644 --- a/velox/expression/tests/utils/ArgumentTypeFuzzer.cpp +++ b/velox/expression/tests/utils/ArgumentTypeFuzzer.cpp @@ -47,16 +47,6 @@ 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; - 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) {