Skip to content

Commit f4a54e3

Browse files
committed
validate cast
1 parent c8b4842 commit f4a54e3

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

velox/connectors/hive/HiveConnector.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ bool testFilters(
309309
template <TypeKind ToKind>
310310
velox::variant convertFromString(const std::optional<std::string>& value) {
311311
if (value.has_value()) {
312+
// No need for casting if ToKind is VARCHAR or VARBINARY.
312313
if constexpr (ToKind == TypeKind::VARCHAR || ToKind == TypeKind::VARBINARY) {
313314
return velox::variant(value.value());
314315
}

velox/substrait/SubstraitToVeloxExpr.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -453,18 +453,6 @@ SubstraitVeloxExprConverter::toVeloxExpr(
453453

454454
std::vector<core::TypedExprPtr> inputs{
455455
toVeloxExpr(castExpr.input(), inputType)};
456-
457-
// TODO: refactor this part for input type validation.
458-
for (const auto& input : inputs) {
459-
switch (input->type()->kind()) {
460-
case TypeKind::ARRAY: {
461-
// Cast from array type is not supported. See CastExpr::applyCast.
462-
VELOX_UNSUPPORTED("Invalid from type in casting: {}", input->type());
463-
}
464-
default: {
465-
}
466-
}
467-
}
468456
return std::make_shared<core::CastTypedExpr>(type, inputs, nullOnFailure);
469457
}
470458

velox/substrait/SubstraitToVeloxPlanValidator.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,28 @@ bool SubstraitToVeloxPlanValidator::validateLiteral(
9494
return true;
9595
}
9696

97+
bool SubstraitToVeloxPlanValidator::validateCast(
98+
const ::substrait::Expression::Cast& castExpr,
99+
const RowTypePtr& inputType) {
100+
std::vector<core::TypedExprPtr> inputs{
101+
exprConverter_->toVeloxExpr(castExpr.input(), inputType)};
102+
103+
// Casting from some types is not supported. See CastExpr::applyCast.
104+
for (const auto& input : inputs) {
105+
switch (input->type()->kind()) {
106+
case TypeKind::ARRAY:
107+
case TypeKind::MAP:
108+
case TypeKind::ROW:
109+
case TypeKind::VARBINARY:
110+
VLOG(1) << "Invalid input type in casting: " << input->type() << ".";
111+
return false;
112+
default: {
113+
}
114+
}
115+
}
116+
return true;
117+
}
118+
97119
bool SubstraitToVeloxPlanValidator::validateExpression(
98120
const ::substrait::Expression& expression,
99121
const RowTypePtr& inputType) {
@@ -104,6 +126,8 @@ bool SubstraitToVeloxPlanValidator::validateExpression(
104126
return validateScalarFunction(expression.scalar_function(), inputType);
105127
case ::substrait::Expression::RexTypeCase::kLiteral:
106128
return validateLiteral(expression.literal(), inputType);
129+
case ::substrait::Expression::RexTypeCase::kCast:
130+
return validateCast(expression.cast(), inputType);
107131
default:
108132
return true;
109133
}

velox/substrait/SubstraitToVeloxPlanValidator.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ class SubstraitToVeloxPlanValidator {
101101
const ::substrait::Expression::ScalarFunction& scalarFunction,
102102
const RowTypePtr& inputType);
103103

104+
/// Validate Substrait Cast expression.
105+
bool validateCast(
106+
const ::substrait::Expression::Cast& castExpr,
107+
const RowTypePtr& inputType);
108+
104109
/// Validate Substrait expression.
105110
bool validateExpression(
106111
const ::substrait::Expression& expression,

0 commit comments

Comments
 (0)