Skip to content

Commit

Permalink
[GLUTEN-5003][VL] Fix Null literal fallback (#5004)
Browse files Browse the repository at this point in the history
  • Loading branch information
WangGuangxin authored Mar 19, 2024
1 parent 91fb95d commit a1e0367
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ class VeloxLiteralSuite extends VeloxWholeStageTransformerSuite {
validateOffloadResult("SELECT struct('Spark', cast(null as int))")
validateOffloadResult("SELECT struct(cast(null as decimal))")
validateOffloadResult("SELECT map('b', 'a', 'e', null)")
validateOffloadResult("SELECT array(null)")
validateOffloadResult("SELECT array(cast(null as int))")
validateOffloadResult("SELECT map(1, null)")
}

test("Scalar Type Literal") {
Expand All @@ -132,9 +135,6 @@ class VeloxLiteralSuite extends VeloxWholeStageTransformerSuite {
}

test("Literal Fallback") {
validateFallbackResult("SELECT array(null)")
validateFallbackResult("SELECT array(cast(null as int))")
validateFallbackResult("SELECT map(1, null)")
validateFallbackResult("SELECT struct(cast(null as struct<a: string>))")
}
}
5 changes: 5 additions & 0 deletions cpp/velox/substrait/SubstraitParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ T SubstraitParser::getLiteralValue(const ::substrait::Expression::Literal& /* li
VELOX_NYI();
}

template <>
std::shared_ptr<void> gluten::SubstraitParser::getLiteralValue(const substrait::Expression_Literal& literal) {
return nullptr;
}

template <>
facebook::velox::UnknownValue gluten::SubstraitParser::getLiteralValue(const substrait::Expression_Literal& literal) {
return UnknownValue();
Expand Down
11 changes: 5 additions & 6 deletions cpp/velox/substrait/SubstraitToVeloxExpr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ ArrayVectorPtr SubstraitVeloxExprConverter::literalsToArrayVector(const ::substr
VELOX_CHECK_GT(childSize, 0, "there should be at least 1 value in list literal.");
auto childLiteral = literal.list().values(0);
auto elementAtFunc = [&](vector_size_t idx) { return literal.list().values(idx); };
auto childVector = literalsToVector(childLiteral, childSize, literal, elementAtFunc);
auto childVector = literalsToVector(childLiteral, childSize, elementAtFunc);
return makeArrayVector(childVector);
}

Expand All @@ -406,22 +406,21 @@ MapVectorPtr SubstraitVeloxExprConverter::literalsToMapVector(const ::substrait:
auto& valueLiteral = literal.map().key_values(0).value();
auto keyAtFunc = [&](vector_size_t idx) { return literal.map().key_values(idx).key(); };
auto valueAtFunc = [&](vector_size_t idx) { return literal.map().key_values(idx).value(); };
auto keyVector = literalsToVector(keyLiteral, childSize, literal, keyAtFunc);
auto valueVector = literalsToVector(valueLiteral, childSize, literal, valueAtFunc);
auto keyVector = literalsToVector(keyLiteral, childSize, keyAtFunc);
auto valueVector = literalsToVector(valueLiteral, childSize, valueAtFunc);
return makeMapVector(keyVector, valueVector);
}

VectorPtr SubstraitVeloxExprConverter::literalsToVector(
const ::substrait::Expression::Literal& childLiteral,
vector_size_t childSize,
const ::substrait::Expression::Literal& literal,
std::function<::substrait::Expression::Literal(vector_size_t /* idx */)> elementAtFunc) {
auto childTypeCase = childLiteral.literal_type_case();
switch (childTypeCase) {
case ::substrait::Expression_Literal::LiteralTypeCase::kNull: {
auto veloxType = SubstraitParser::parseType(literal.null());
auto veloxType = SubstraitParser::parseType(childLiteral.null());
auto kind = veloxType->kind();
return VELOX_DYNAMIC_SCALAR_TYPE_DISPATCH(constructFlatVector, kind, elementAtFunc, childSize, veloxType, pool_);
return VELOX_DYNAMIC_SCALAR_TYPE_DISPATCH_ALL(constructFlatVector, kind, elementAtFunc, childSize, veloxType, pool_);
}
case ::substrait::Expression_Literal::LiteralTypeCase::kIntervalDayToSecond:
return constructFlatVector<TypeKind::BIGINT>(elementAtFunc, childSize, INTERVAL_DAY_TIME(), pool_);
Expand Down
1 change: 0 additions & 1 deletion cpp/velox/substrait/SubstraitToVeloxExpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class SubstraitVeloxExprConverter {
VectorPtr literalsToVector(
const ::substrait::Expression::Literal& childLiteral,
vector_size_t childSize,
const ::substrait::Expression::Literal& literal,
std::function<::substrait::Expression::Literal(vector_size_t /* idx */)> elementAtFunc);
RowVectorPtr literalsToRowVector(const ::substrait::Expression::Literal& structLiteral);

Expand Down

0 comments on commit a1e0367

Please sign in to comment.