Skip to content

Commit

Permalink
[OPPRO-153] Fix int variant (facebookincubator#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
rui-mo authored and zhejiangxiaomai committed Apr 20, 2023
1 parent 3499429 commit c7aba62
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
30 changes: 24 additions & 6 deletions velox/substrait/SubstraitToVeloxPlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1380,26 +1380,26 @@ void SubstraitVeloxPlanConverter::createNotEqualFilter(
variant notVariant,
bool nullAllowed,
std::vector<std::unique_ptr<FilterType>>& colFilters) {
using T = typename RangeTraits<KIND>::NativeType;
using NativeType = typename RangeTraits<KIND>::NativeType;
using RangeType = typename RangeTraits<KIND>::RangeType;

// Value > lower
std::unique_ptr<FilterType> lowerFilter = std::make_unique<RangeType>(
notVariant.value<T>(), /*lower*/
notVariant.value<NativeType>(), /*lower*/
false, /*lowerUnbounded*/
true, /*lowerExclusive*/
getMax<T>(), /*upper*/
getMax<NativeType>(), /*upper*/
true, /*upperUnbounded*/
false, /*upperExclusive*/
nullAllowed); /*nullAllowed*/
colFilters.emplace_back(std::move(lowerFilter));

// Value < upper
std::unique_ptr<FilterType> upperFilter = std::make_unique<RangeType>(
getLowest<T>(), /*lower*/
getLowest<NativeType>(), /*lower*/
true, /*lowerUnbounded*/
false, /*lowerExclusive*/
notVariant.value<T>(), /*upper*/
notVariant.value<NativeType>(), /*upper*/
false, /*upperUnbounded*/
true, /*upperExclusive*/
nullAllowed); /*nullAllowed*/
Expand Down Expand Up @@ -1445,6 +1445,24 @@ void SubstraitVeloxPlanConverter::setInFilter<TypeKind::BIGINT>(
common::createBigintValues(values, nullAllowed);
}

template <>
void SubstraitVeloxPlanConverter::setInFilter<TypeKind::INTEGER>(
const std::vector<variant>& variants,
bool nullAllowed,
const std::string& inputName,
connector::hive::SubfieldFilters& filters) {
// Use bigint values for int type.
std::vector<int64_t> values;
values.reserve(variants.size());
for (const auto& variant : variants) {
// Use the matched type to get value from variant.
int64_t value = variant.value<int32_t>();
values.emplace_back(value);
}
filters[common::Subfield(inputName)] =
common::createBigintValues(values, nullAllowed);
}

template <>
void SubstraitVeloxPlanConverter::setInFilter<TypeKind::VARCHAR>(
const std::vector<variant>& variants,
Expand Down Expand Up @@ -1640,7 +1658,7 @@ connector::hive::SubfieldFilters SubstraitVeloxPlanConverter::mapToFilters(
auto inputType = inputTypeList[colIdx];
switch (inputType->kind()) {
case TypeKind::INTEGER:
constructSubfieldFilters<TypeKind::BIGINT, common::BigintRange>(
constructSubfieldFilters<TypeKind::INTEGER, common::BigintRange>(
colIdx, inputNameList[colIdx], colInfoMap[colIdx], filters);
break;
case TypeKind::BIGINT:
Expand Down
2 changes: 1 addition & 1 deletion velox/substrait/TypeUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ template <>
struct RangeTraits<TypeKind::INTEGER> {
using RangeType = common::BigintRange;
using MultiRangeType = common::BigintMultiRange;
using NativeType = int64_t;
using NativeType = int32_t;
};

template <>
Expand Down

0 comments on commit c7aba62

Please sign in to comment.