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 Sep 1, 2022
1 parent 6209262 commit 53b301f
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 @@ -1360,26 +1360,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 @@ -1425,6 +1425,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 @@ -1630,7 +1648,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 @@ -33,7 +33,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 53b301f

Please sign in to comment.