diff --git a/velox/substrait/tests/Substrait2VeloxPlanConversionTest.cpp b/velox/substrait/tests/Substrait2VeloxPlanConversionTest.cpp index 0f38a0777007..1c784a117579 100644 --- a/velox/substrait/tests/Substrait2VeloxPlanConversionTest.cpp +++ b/velox/substrait/tests/Substrait2VeloxPlanConversionTest.cpp @@ -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); + +} diff --git a/velox/substrait/tests/data/filter_upper.json b/velox/substrait/tests/data/filter_upper.json new file mode 100644 index 000000000000..7b4211fbf008 --- /dev/null +++ b/velox/substrait/tests/data/filter_upper.json @@ -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"] + } + } + ] +} diff --git a/velox/type/Filter.h b/velox/type/Filter.h index c76f1f18b3c4..b841c54c270b 100644 --- a/velox/type/Filter.h +++ b/velox/type/Filter.h @@ -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(lower, std::numeric_limits::min())), - upper32_(std::min(upper, std::numeric_limits::max())), - lower16_(std::max(lower, std::numeric_limits::min())), - upper16_(std::min(upper, std::numeric_limits::max())), + lower32_(std::max(lower_, std::numeric_limits::min())), + upper32_(std::min(upper_, std::numeric_limits::max())), + lower16_(std::max(lower_, std::numeric_limits::min())), + upper16_(std::min(upper_, std::numeric_limits::max())), isSingleValue_(upper_ == lower_) {} std::unique_ptr clone(