larry98 commented on code in PR #43761:
URL: https://github.com/apache/arrow/pull/43761#discussion_r1729474776
##########
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();
+
+ Simplify{is_in(field_ref("i32"), int32(), "[1,3,5,7,9]",
null_matching_behavior)}
+ .WithGuarantee(
+ and_(less_equal(field_ref("i32"), literal(7)),
+ greater(field_ref("i32"), literal(4))))
+ .Expect(is_in(field_ref("i32"), int32(), "[5,7]",
null_matching_behavior));
+
+ Simplify{is_in(field_ref("u32"), int8(), "[1,3,5,7,9]",
null_matching_behavior)}
+ .WithGuarantee(greater(field_ref("u32"), literal(3)))
+ .Expect(is_in(field_ref("u32"), int8(), "[5,7,9]",
null_matching_behavior));
+
+ Simplify{is_in(field_ref("u32"), int64(), "[1,3,5,7,9]",
null_matching_behavior)}
+ .WithGuarantee(greater(field_ref("u32"), literal(3)))
+ .Expect(is_in(field_ref("u32"), int64(), "[5,7,9]",
null_matching_behavior));
+ }
+
+ Simplify{
+ is_in(field_ref("i32"), int32(), "[1,3,5,7,9]",
SetLookupOptions::INCONCLUSIVE)
+ }
+ .WithGuarantee(greater(field_ref("i32"), literal(3)))
+ .ExpectUnchanged();
+}
+
TEST(Expression, SimplifyThenExecute) {
Review Comment:
Added a test to actually execute against arrays. For value sets containing
nulls, I left a comment about this above.
--
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]