Skip to content

Commit

Permalink
Support selecting subfield from struct (oap-project#38)
Browse files Browse the repository at this point in the history
Fix bigint range (oap-project#40)
  • Loading branch information
rui-mo authored and zhejiangxiaomai committed Oct 20, 2022
1 parent 067834e commit 29fca4e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
33 changes: 29 additions & 4 deletions velox/substrait/SubstraitToVeloxExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,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<int32_t> 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<core::FieldAccessTypedExpr>(
inputTypes[colIdx],
std::make_shared<core::InputTypedExpr>(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<core::FieldAccessTypedExpr>(
inputColumnType->childAt(childIdx.value()),
std::make_shared<core::FieldAccessTypedExpr>(
inputTypes[colIdx], inputNames[colIdx]),
inputColumnType->nameOf(childIdx.value()));
} else {
VELOX_FAIL("RowType expected.");
}
}
break;
}
default:
VELOX_NYI(
Expand Down Expand Up @@ -120,6 +144,7 @@ SubstraitVeloxExprConverter::toVeloxExpr(
if (veloxFunction == "alias") {
return toAliasExpr(std::move(params));
}

if (veloxFunction == "is_not_null") {
return toIsNotNullExpr(std::move(params), toVeloxType(typeName));
}
Expand Down
1 change: 0 additions & 1 deletion velox/type/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,6 @@ std::unique_ptr<Filter> createBigintValuesFilter(
min, max, values, nullAllowed);
}


std::unique_ptr<Filter> createBigintValues(
const std::vector<int64_t>& values,
bool nullAllowed) {
Expand Down
4 changes: 2 additions & 2 deletions velox/type/Filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int64_t>(lower, std::numeric_limits<int32_t>::min())),
upper32_(std::min<int64_t>(upper, std::numeric_limits<int32_t>::max())),
lower16_(std::max<int64_t>(lower, std::numeric_limits<int16_t>::min())),
Expand Down

0 comments on commit 29fca4e

Please sign in to comment.