From 844f06596b778ac99c5c9f02aeab39af20798288 Mon Sep 17 00:00:00 2001 From: rui-mo Date: Thu, 4 Apr 2024 10:56:47 +0800 Subject: [PATCH] Add test --- velox/functions/prestosql/DecimalFunctions.cpp | 3 ++- velox/functions/prestosql/tests/DecimalArithmeticTest.cpp | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/velox/functions/prestosql/DecimalFunctions.cpp b/velox/functions/prestosql/DecimalFunctions.cpp index 747163a9fc36b..c772d72e79bd7 100644 --- a/velox/functions/prestosql/DecimalFunctions.cpp +++ b/velox/functions/prestosql/DecimalFunctions.cpp @@ -364,7 +364,8 @@ void registerDecimalMultiply(const std::string& prefix) { exec::SignatureVariable( S3::name(), fmt::format( - "{a_scale} + {b_scale}", + "{a_scale} + {b_scale}", /*When its value exceeds precision, + function creation fails.*/ fmt::arg("a_scale", S1::name()), fmt::arg("b_scale", S2::name())), exec::ParameterType::kIntegerParameter), diff --git a/velox/functions/prestosql/tests/DecimalArithmeticTest.cpp b/velox/functions/prestosql/tests/DecimalArithmeticTest.cpp index 2563860ae8719..954a011c8f928 100644 --- a/velox/functions/prestosql/tests/DecimalArithmeticTest.cpp +++ b/velox/functions/prestosql/tests/DecimalArithmeticTest.cpp @@ -291,6 +291,14 @@ TEST_F(DecimalArithmeticTest, multiply) { HugeInt::build(0x08FFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)}, DECIMAL(38, 0))}), "Decimal overflow. Value '119630519620642428561342635425231011830' is not in the range of Decimal Type"); + + // The sum of input scales exceeds result precision. + VELOX_ASSERT_THROW( + evaluate( + "c0 * c0", + makeRowVector( + {makeFlatVector({1000, 2000}, DECIMAL(38, 30))})), + ""); } TEST_F(DecimalArithmeticTest, decimalDivTest) {