Skip to content

Commit

Permalink
Allow binding fixed precision or scale for decimal type (facebookincu…
Browse files Browse the repository at this point in the history
…bator#9044)

Summary:
Fixes facebookincubator#9029

Pull Request resolved: facebookincubator#9044

Reviewed By: Yuhta

Differential Revision: D54800731

Pulled By: mbasmanova

fbshipit-source-id: 7c15beb9c04c377f543612b1db6f2f0134c419b1
  • Loading branch information
marin-ma authored and facebook-github-bot committed Mar 12, 2024
1 parent 86f559c commit de54d1e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions velox/expression/SignatureBinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions velox/expression/tests/SignatureBinderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit de54d1e

Please sign in to comment.