From de54d1e18f6e5bed8cbca2cdddc8043081a4c8a2 Mon Sep 17 00:00:00 2001 From: "Ma, Rong" Date: Tue, 12 Mar 2024 15:53:40 -0700 Subject: [PATCH] Allow binding fixed precision or scale for decimal type (#9044) Summary: Fixes https://github.com/facebookincubator/velox/issues/9029 Pull Request resolved: https://github.com/facebookincubator/velox/pull/9044 Reviewed By: Yuhta Differential Revision: D54800731 Pulled By: mbasmanova fbshipit-source-id: 7c15beb9c04c377f543612b1db6f2f0134c419b1 --- velox/expression/SignatureBinder.cpp | 3 +++ .../expression/tests/SignatureBinderTest.cpp | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/velox/expression/SignatureBinder.cpp b/velox/expression/SignatureBinder.cpp index 6ec60dcbe749..4ea670d4d195 100644 --- a/velox/expression/SignatureBinder.cpp +++ b/velox/expression/SignatureBinder.cpp @@ -138,6 +138,9 @@ bool SignatureBinder::tryBind() { bool SignatureBinderBase::checkOrSetIntegerParameter( const std::string& parameterName, int value) { + if (isPositiveInteger(parameterName)) { + return atoi(parameterName.c_str()) == value; + } if (!variables().count(parameterName)) { // Return false if the parameter is not found in the signature. return false; diff --git a/velox/expression/tests/SignatureBinderTest.cpp b/velox/expression/tests/SignatureBinderTest.cpp index 6c481ca4b35e..4eba91f38455 100644 --- a/velox/expression/tests/SignatureBinderTest.cpp +++ b/velox/expression/tests/SignatureBinderTest.cpp @@ -240,6 +240,31 @@ TEST(SignatureBinderTest, decimals) { "Type variables cannot have constraints"); } } + // Scalar function signature with fixed scale. + { + { + auto signature = exec::FunctionSignatureBuilder() + .integerVariable("precision") + .returnType("boolean") + .argumentType("DECIMAL(precision, 6)") + .build(); + testSignatureBinder(signature, {DECIMAL(11, 6)}, BOOLEAN()); + assertCannotResolve(signature, {DECIMAL(11, 8)}); + } + { + auto signature = exec::FunctionSignatureBuilder() + .integerVariable("precision") + .integerVariable("scale") + .returnType("DECIMAL(precision, scale)") + .argumentType("DECIMAL(precision, 6)") + .argumentType("DECIMAL(18, scale)") + .build(); + testSignatureBinder( + signature, {DECIMAL(11, 6), DECIMAL(18, 4)}, DECIMAL(11, 4)); + assertCannotResolve(signature, {DECIMAL(11, 6), DECIMAL(20, 4)}); + assertCannotResolve(signature, {DECIMAL(11, 8), DECIMAL(18, 4)}); + } + } } TEST(SignatureBinderTest, computation) {