larry98 commented on code in PR #43761:
URL: https://github.com/apache/arrow/pull/43761#discussion_r1735316623
##########
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:
I see, that sounds reasonable to me. I added new tests for nullable
guarantees and nulls in the value set for all of the different null matching
behaviors.
--
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]