JeonDaehong commented on code in PR #3717:
URL: https://github.com/apache/iceberg-rust/pull/3717#discussion_r4642906736


##########
crates/iceberg/src/expr/predicate.rs:
##########
@@ -456,10 +456,17 @@ impl Bind for Predicate {
             }
             Predicate::Set(expr) => {
                 let bound_expr = expr.bind(schema, case_sensitive)?;
+                // A literal outside the field type's range equals no value of 
the field.

Review Comment:
   Same filter as Java's `bindInOperation` (`lit != Literals.aboveMax() && lit 
!= Literals.belowMin()`), so `IN` and `NOT IN` now bind the same way on both 
sides.



##########
crates/iceberg/src/expr/predicate.rs:
##########
@@ -1390,6 +1397,62 @@ mod tests {
         assert!(bound_expr.is_err());
     }
 
+    #[test]
+    fn test_bind_in_drops_out_of_range_literals() {
+        let schema = table_schema_simple();
+        // int32 holds -2147483648 to 2147483647
+        let expr = Reference::new("bar").is_in([
+            Datum::long(10),
+            Datum::long(20),
+            Datum::long(2147483648i64),
+            Datum::long(-2147483649i64),
+        ]);
+        let bound_expr = expr.bind(schema, true).unwrap();
+        assert_eq!(&format!("{bound_expr}"), "bar IN (20, 10)");
+        test_bound_predicate_serialize_diserialize(bound_expr);
+    }
+
+    #[test]
+    fn test_bind_in_one_literal_in_range() {
+        let schema = table_schema_simple();
+        let expr = Reference::new("bar").is_in([Datum::long(10), 
Datum::long(2147483648i64)]);
+        let bound_expr = expr.bind(schema, true).unwrap();
+        assert_eq!(&format!("{bound_expr}"), "bar = 10");
+        test_bound_predicate_serialize_diserialize(bound_expr);
+    }
+
+    #[test]
+    fn test_bind_in_only_out_of_range_literals() {
+        let schema = table_schema_simple();
+        let expr =
+            Reference::new("bar").is_in([Datum::long(2147483648i64), 
Datum::long(-2147483649i64)]);
+        let bound_expr = expr.bind(schema, true).unwrap();
+        assert_eq!(&format!("{bound_expr}"), "False");
+        test_bound_predicate_serialize_diserialize(bound_expr);
+    }
+
+    #[test]
+    fn test_bind_not_in_drops_out_of_range_literals() {
+        let schema = table_schema_simple();
+        let expr = Reference::new("bar").is_not_in([
+            Datum::long(10),
+            Datum::long(20),
+            Datum::long(2147483648i64),
+        ]);
+        let bound_expr = expr.bind(schema, true).unwrap();
+        assert_eq!(&format!("{bound_expr}"), "bar NOT IN (20, 10)");
+        test_bound_predicate_serialize_diserialize(bound_expr);
+    }
+
+    #[test]
+    fn test_bind_not_in_only_out_of_range_literals() {

Review Comment:
   One thing I noticed reading a file with an optional `b = [10, NULL, 20, 30]` 
on this branch: `b NOT IN (10, 11)` and `b != 10` both skip the NULL row, but 
`b NOT IN (2147483648, 2147483649)` binds to `True` and returns it. Java also 
binds this to `alwaysTrue`, so it matches Java's binding, but within 
iceberg-rust a set that ends up empty now treats NULL differently from one that 
doesn't. Would binding it to `b IS NOT NULL` for an optional field be closer to 
what the reader does for `NOT IN`, or is matching Java preferred here?



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to