Skip to content

Commit fd2c951

Browse files
add literal validate
1 parent 96535d6 commit fd2c951

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

velox/substrait/SubstraitToVeloxPlanValidator.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ bool SubstraitToVeloxPlanValidator::validateInputTypes(
5151
}
5252

5353
bool SubstraitToVeloxPlanValidator::validateRound(
54-
const ::substrait::Expression::ScalarFunction& scalarFunction,
55-
const RowTypePtr& inputType) {
54+
const ::substrait::Expression::ScalarFunction& scalarFunction,
55+
const RowTypePtr& inputType) {
5656
const auto& arguments = scalarFunction.arguments();
5757
if (arguments.size() < 2) {
5858
return false;
@@ -68,30 +68,42 @@ bool SubstraitToVeloxPlanValidator::validateRound(
6868
case ::substrait::Expression_Literal::LiteralTypeCase::kI64:
6969
return (arguments[1].value().literal().i64() >= 0);
7070
default:
71-
VELOX_NYI("Round scale validation is not supported for type case '{}'", typeCase);
71+
VELOX_NYI(
72+
"Round scale validation is not supported for type case '{}'",
73+
typeCase);
7274
}
7375
}
7476

7577
bool SubstraitToVeloxPlanValidator::validateScalarFunction(
7678
const ::substrait::Expression::ScalarFunction& scalarFunction,
7779
const RowTypePtr& inputType) {
78-
const auto& veloxFunction =
79-
subParser_->findVeloxFunction(
80-
planConverter_->getFunctionMap(), scalarFunction.function_reference());
80+
const auto& veloxFunction = subParser_->findVeloxFunction(
81+
planConverter_->getFunctionMap(), scalarFunction.function_reference());
8182
if (veloxFunction == "round") {
8283
return validateRound(scalarFunction, inputType);
8384
}
8485
return true;
8586
}
8687

88+
bool SubstraitToVeloxPlanValidator::validateLiteral(
89+
const ::substrait::Expression_Literal& literal,
90+
const RowTypePtr& inputType) {
91+
if (literal.has_list() && literal.list().values_size() == 0) {
92+
return false;
93+
}
94+
return true;
95+
}
96+
8797
bool SubstraitToVeloxPlanValidator::validateExpression(
8898
const ::substrait::Expression& expression,
8999
const RowTypePtr& inputType) {
90-
std::shared_ptr<const core::ITypedExpr> veloxExpr;
100+
std::shared_ptr<const core::ITypedExpr> veloxExpr;
91101
auto typeCase = expression.rex_type_case();
92102
switch (typeCase) {
93103
case ::substrait::Expression::RexTypeCase::kScalarFunction:
94104
return validateScalarFunction(expression.scalar_function(), inputType);
105+
case ::substrait::Expression::RexTypeCase::kLiteral:
106+
return validateLiteral(expression.literal(), inputType);
95107
default:
96108
return true;
97109
}
@@ -245,8 +257,9 @@ bool SubstraitToVeloxPlanValidator::validate(
245257
windowFunction.window_type());
246258
}
247259

248-
bool boundTypeSupported = validateBoundType(windowFunction.upper_bound()) &&
249-
validateBoundType(windowFunction.lower_bound());
260+
bool boundTypeSupported =
261+
validateBoundType(windowFunction.upper_bound()) &&
262+
validateBoundType(windowFunction.lower_bound());
250263
if (!boundTypeSupported) {
251264
return false;
252265
}

velox/substrait/SubstraitToVeloxPlanValidator.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,23 @@ class SubstraitToVeloxPlanValidator {
9393

9494
/// Validate the round scalar function.
9595
bool validateRound(
96-
const ::substrait::Expression::ScalarFunction& scalarFunction,
97-
const RowTypePtr& inputType);
96+
const ::substrait::Expression::ScalarFunction& scalarFunction,
97+
const RowTypePtr& inputType);
9898

9999
/// Validate Substrait scarlar function.
100100
bool validateScalarFunction(
101-
const ::substrait::Expression::ScalarFunction& scalarFunction,
102-
const RowTypePtr& inputType);
101+
const ::substrait::Expression::ScalarFunction& scalarFunction,
102+
const RowTypePtr& inputType);
103103

104104
/// Validate Substrait expression.
105105
bool validateExpression(
106-
const ::substrait::Expression& expression,
107-
const RowTypePtr& inputType);
106+
const ::substrait::Expression& expression,
107+
const RowTypePtr& inputType);
108+
109+
/// Validate Substrait literal.
110+
bool validateLiteral(
111+
const ::substrait::Expression_Literal& literal,
112+
const RowTypePtr& inputType);
108113
};
109114

110115
} // namespace facebook::velox::substrait

0 commit comments

Comments
 (0)