larry98 commented on code in PR #43761:
URL: https://github.com/apache/arrow/pull/43761#discussion_r1729462700
##########
cpp/src/arrow/compute/expression_test.cc:
##########
@@ -1616,6 +1616,82 @@ TEST(Expression,
SimplifyWithComparisonAndNullableCaveat) {
true_unless_null(field_ref("i32")))); // not satisfiable, will drop
row group
}
+TEST(Expression, SimplifyIsIn) {
+ auto is_in = [](Expression field, std::shared_ptr<DataType> value_set_type,
+ std::string json_array,
+ SetLookupOptions::NullMatchingBehavior
null_matching_behavior) {
+ SetLookupOptions options{ArrayFromJSON(value_set_type, json_array),
+ null_matching_behavior};
+ return call("is_in", {field}, options);
+ };
+
+ for (SetLookupOptions::NullMatchingBehavior null_matching_behavior :
+ {SetLookupOptions::MATCH, SetLookupOptions::SKIP,
SetLookupOptions::EMIT_NULL}) {
+ Simplify{is_in(field_ref("i32"), int32(), "[]", null_matching_behavior)}
+ .WithGuarantee(greater(field_ref("i32"), literal(2)))
+ .Expect(false);
+
+ Simplify{is_in(field_ref("i32"), int32(), "[null]",
null_matching_behavior)}
+ .WithGuarantee(greater(field_ref("i32"), literal(2)))
+ .Expect(false);
+
+ Simplify{is_in(field_ref("i32"), int32(), "[1,3,5,7,9]",
null_matching_behavior)}
+ .WithGuarantee(equal(field_ref("i32"), literal(7)))
+ .Expect(true);
+
+ Simplify{is_in(field_ref("i32"), int32(), "[1,3,5,7,9]",
null_matching_behavior)}
+ .WithGuarantee(equal(field_ref("i32"), literal(6)))
+ .Expect(false);
+
+ Simplify{is_in(field_ref("i32"), int32(), "[1,3,5,7,9]",
null_matching_behavior)}
+ .WithGuarantee(greater(field_ref("i32"), literal(3)))
+ .Expect(is_in(field_ref("i32"), int32(), "[5,7,9]",
null_matching_behavior));
+
+ Simplify{
+ is_in(field_ref("i32"), int32(), "[1,null,3,5,null,7,9]",
null_matching_behavior)
+ }
+ .WithGuarantee(greater(field_ref("i32"), literal(3)))
+ .Expect(is_in(field_ref("i32"), int32(), "[5,7,9]",
null_matching_behavior));
+
+ Simplify{is_in(field_ref("i32"), int32(), "[1,3,5,7,9]",
null_matching_behavior)}
+ .WithGuarantee(greater(field_ref("i32"), literal(9)))
+ .Expect(false);
+
+ Simplify{is_in(field_ref("i32"), int32(), "[1,3,5,7,9]",
null_matching_behavior)}
+ .WithGuarantee(less_equal(field_ref("i32"), literal(0)))
+ .Expect(false);
+
+ Simplify{is_in(field_ref("i32"), int32(), "[1,3,5,7,9]",
null_matching_behavior)}
+ .WithGuarantee(greater(field_ref("i32"), literal(0)))
+ .ExpectUnchanged();
+
+ Simplify{is_in(field_ref("i32"), int32(), "[1,3,5,7,9]",
null_matching_behavior)}
+ .WithGuarantee(
+ or_(equal(field_ref("i32"), literal(3)),
is_null(field_ref("i32"))))
+ .ExpectUnchanged();
+
Review Comment:
The original intention was to not support simplification if nulls in the
value set cannot be dropped (either the guarantee is nullable or the null
matching behavior is `INCONCLUSIVE`). This is because in the optimized
implementation where we binary search and slice the value set array, slicing
the front would drop nulls (assuming they are placed at the end) so we would
have to reallocate a new array for the simplified value set.
Do you think we ought to support nulls in the value set, and if so any
thoughts on how we'd continue to support this with the binary search/slice
implementation?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]