Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow different decimal types in switch expr #7088

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions velox/expression/SwitchExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -254,13 +259,17 @@ TypePtr SwitchExpr::resolveType(const std::vector<TypePtr>& 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;
Expand Down