diff --git a/velox/substrait/SubstraitToVeloxExpr.cpp b/velox/substrait/SubstraitToVeloxExpr.cpp index 7a2dc93a4fa10..563443de41f48 100644 --- a/velox/substrait/SubstraitToVeloxExpr.cpp +++ b/velox/substrait/SubstraitToVeloxExpr.cpp @@ -159,19 +159,43 @@ SubstraitVeloxExprConverter::toVeloxExpr( case ::substrait::Expression::FieldReference::ReferenceTypeCase:: kDirectReference: { const auto& dRef = substraitField.direct_reference(); + VELOX_CHECK(dRef.has_struct_field(), "Struct field expected."); int32_t colIdx = subParser_->parseReferenceSegment(dRef); + std::optional childIdx; + if (dRef.struct_field().has_child()) { + childIdx = + subParser_->parseReferenceSegment(dRef.struct_field().child()); + } + + const auto& inputTypes = inputType->children(); const auto& inputNames = inputType->names(); const int64_t inputSize = inputNames.size(); - if (colIdx <= inputSize) { - const auto& inputTypes = inputType->children(); - // Convert type to row. + + if (colIdx >= inputSize) { + VELOX_FAIL("Missing the column with id '{}' .", colIdx); + } + + if (!childIdx.has_value()) { return std::make_shared( inputTypes[colIdx], std::make_shared(inputTypes[colIdx]), inputNames[colIdx]); } else { - VELOX_FAIL("Missing the column with id '{}' .", colIdx); + // Select a subfield in a struct by name. + if (auto inputColumnType = asRowType(inputTypes[colIdx])) { + if (childIdx.value() >= inputColumnType->size()) { + VELOX_FAIL("Missing the subfield with id '{}' .", childIdx.value()); + } + return std::make_shared( + inputColumnType->childAt(childIdx.value()), + std::make_shared( + inputTypes[colIdx], inputNames[colIdx]), + inputColumnType->nameOf(childIdx.value())); + } else { + VELOX_FAIL("RowType expected."); + } } + break; } default: VELOX_NYI( @@ -250,6 +274,7 @@ SubstraitVeloxExprConverter::toVeloxExpr( if (veloxFunction == "alias") { return toAliasExpr(std::move(params)); } + if (veloxFunction == "is_not_null") { return toIsNotNullExpr(std::move(params), toVeloxType(typeName)); } diff --git a/velox/type/Filter.cpp b/velox/type/Filter.cpp index f30e900cf62a3..74d069139a4dc 100644 --- a/velox/type/Filter.cpp +++ b/velox/type/Filter.cpp @@ -574,7 +574,6 @@ std::unique_ptr createBigintValuesFilter( min, max, values, nullAllowed); } - std::unique_ptr createBigintValues( const std::vector& values, bool nullAllowed) { diff --git a/velox/type/Filter.h b/velox/type/Filter.h index 4b7adf3f5bea2..c76f1f18b3c4b 100644 --- a/velox/type/Filter.h +++ b/velox/type/Filter.h @@ -564,8 +564,8 @@ class BigintRange final : public Filter { bool upperExclusive, bool nullAllowed) : Filter(true, nullAllowed, FilterKind::kBigintRange), - lower_(lowerExclusive ? lower - 1 : lower), - upper_(upperExclusive ? upper + 1 : upper), + lower_(lowerExclusive ? lower + 1 : lower), + upper_(upperExclusive ? upper - 1 : upper), lower32_(std::max(lower, std::numeric_limits::min())), upper32_(std::min(upper, std::numeric_limits::max())), lower16_(std::max(lower, std::numeric_limits::min())),