diff --git a/velox/expression/SwitchExpr.cpp b/velox/expression/SwitchExpr.cpp index 5f6d493ad9a4c..dc1431b531223 100644 --- a/velox/expression/SwitchExpr.cpp +++ b/velox/expression/SwitchExpr.cpp @@ -49,11 +49,16 @@ SwitchExpr::SwitchExpr( // Apply type checking. auto typeExpected = resolveType(inputTypes); - VELOX_CHECK( - *typeExpected == *this->type(), - "Switch expression type different than then clause. Expected {} but got Actual {}.", - typeExpected->toString(), - this->type()->toString()); + if (typeExpected->isDecimal()) { + // Regard decimal types as the same regardless of precision and scale. + VELOX_CHECK(this->type()->isDecimal()); + } else { + VELOX_CHECK( + *typeExpected == *this->type(), + "Switch expression type different than then clause. Expected {} but got Actual {}.", + typeExpected->toString(), + this->type()->toString()); + } } void SwitchExpr::evalSpecialForm( @@ -254,13 +259,17 @@ TypePtr SwitchExpr::resolveType(const std::vector& argTypes) { if (hasElse) { auto& elseClauseType = argTypes.back(); - - VELOX_CHECK( - *elseClauseType == *expressionType, - "Else clause of a SWITCH statement must have the same type as 'then' clauses. " - "Expected {}, but got {}.", - expressionType->toString(), - elseClauseType->toString()); + if (elseClauseType->isDecimal()) { + // Regard decimals as the same type regardless of precision and scale. + VELOX_CHECK(expressionType->isDecimal()); + } else { + VELOX_CHECK( + *elseClauseType == *expressionType, + "Else clause of a SWITCH statement must have the same type as 'then' clauses. " + "Expected {}, but got {}.", + expressionType->toString(), + elseClauseType->toString()); + } } return expressionType;