Skip to content

Commit

Permalink
Fix filter bound in BigintRange (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinchengchenghh authored and zhejiangxiaomai committed Jan 11, 2023
1 parent db3df7e commit f191830
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 4 deletions.
14 changes: 14 additions & 0 deletions velox/substrait/tests/Substrait2VeloxPlanConversionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,17 @@ TEST_F(Substrait2VeloxPlanConversionTest, ifthenTest) {
" -- TableScan[table: hive_table, range filters: [(hd_buy_potential, Filter(MultiRange, deterministic, null not allowed)), (hd_demo_sk, Filter(IsNotNull, deterministic, null not allowed)), (hd_vehicle_count, BigintRange: [1, 9223372036854775807] no nulls)], remaining filter: (if(greaterthan(ROW[\"hd_vehicle_count\"],0),greaterthan(divide(cast ROW[\"hd_dep_count\"] as DOUBLE,cast ROW[\"hd_vehicle_count\"] as DOUBLE),1.2)))] -> n0_0:BIGINT, n0_1:VARCHAR, n0_2:BIGINT, n0_3:BIGINT\n",
planNode->toString(true, true));
}

TEST_F(Substrait2VeloxPlanConversionTest, filterUpper) {
std::string subPlanPath =
getDataFilePath("velox/substrait/tests", "data/filter_upper.json");

::substrait::Plan substraitPlan;
JsonToProtoConverter::readFromFile(subPlanPath, substraitPlan);

// Convert to Velox PlanNode.
facebook::velox::substrait::SubstraitVeloxPlanConverter planConverter(
pool_.get());
auto planNode = planConverter.toVeloxPlan(substraitPlan);

}
137 changes: 137 additions & 0 deletions velox/substrait/tests/data/filter_upper.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
{
"extensions": [{
"extensionFunction": {
"name": "is_not_null:opt_bool_i32"
}
}, {
"extensionFunction": {
"functionAnchor": 2,
"name": "and:opt_bool_bool"
}
}, {
"extensionFunction": {
"functionAnchor": 1,
"name": "lt:opt_i32_i32"
}
}
],
"relations": [{
"root": {
"input": {
"project": {
"common": {
"direct": {}
},
"input": {
"read": {
"common": {
"direct": {}
},
"baseSchema": {
"names": ["key"],
"struct": {
"types": [{
"i32": {
"nullability": "NULLABILITY_NULLABLE"
}
}
]
},
"partitionColumns": {
"columnType": ["NORMAL_COL"]
}
},
"filter": {
"scalarFunction": {
"functionReference": 2,
"outputType": {
"bool": {
"nullability": "NULLABILITY_NULLABLE"
}
},
"arguments": [{
"value": {
"scalarFunction": {
"outputType": {
"bool": {
"nullability": "NULLABILITY_REQUIRED"
}
},
"arguments": [{
"value": {
"selection": {
"directReference": {
"structField": {}
}
}
}
}
]
}
}
}, {
"value": {
"scalarFunction": {
"functionReference": 1,
"outputType": {
"bool": {
"nullability": "NULLABILITY_NULLABLE"
}
},
"arguments": [{
"value": {
"selection": {
"directReference": {
"structField": {}
}
}
}
}, {
"value": {
"literal": {
"i32": 3
}
}
}
]
}
}
}
]
}
},
"localFiles": {
"items": [{
"uriFile": "file:///tmp/file.parquet",
"length": "1486",
"parquet": {}
}
]
}
}
},
"expressions": [{
"cast": {
"type": {
"string": {
"nullability": "NULLABILITY_NULLABLE"
}
},
"input": {
"selection": {
"directReference": {
"structField": {}
}
}
},
"failureBehavior": "FAILURE_BEHAVIOR_RETURN_NULL"
}
}
]
}
},
"names": ["key#173"]
}
}
]
}
8 changes: 4 additions & 4 deletions velox/type/Filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -566,10 +566,10 @@ class BigintRange final : public Filter {
: Filter(true, nullAllowed, FilterKind::kBigintRange),
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())),
upper16_(std::min<int64_t>(upper, std::numeric_limits<int16_t>::max())),
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())),
upper16_(std::min<int64_t>(upper_, std::numeric_limits<int16_t>::max())),
isSingleValue_(upper_ == lower_) {}

std::unique_ptr<Filter> clone(
Expand Down

0 comments on commit f191830

Please sign in to comment.