sdd commented on code in PR #231:
URL: https://github.com/apache/iceberg-rust/pull/231#discussion_r1517243146


##########
crates/iceberg/src/expr/predicate.rs:
##########
@@ -406,13 +640,239 @@ mod tests {
 
     #[test]
     fn test_predicate_negate_set() {
-        let expression = 
Reference::new("a").is_in(HashSet::from([Datum::long(5), Datum::long(6)]));
+        let expression = Reference::new("a").is_in([Datum::long(5), 
Datum::long(6)]);
 
-        let expected =
-            Reference::new("a").is_not_in(HashSet::from([Datum::long(5), 
Datum::long(6)]));
+        let expected = Reference::new("a").is_not_in([Datum::long(5), 
Datum::long(6)]);
 
         let result = expression.negate();
 
         assert_eq!(result, expected);
     }
+
+    fn table_schema_simple() -> SchemaRef {
+        Arc::new(
+            Schema::builder()
+                .with_schema_id(1)
+                .with_identifier_field_ids(vec![2])
+                .with_fields(vec![
+                    NestedField::optional(1, "foo", 
Type::Primitive(PrimitiveType::String)).into(),
+                    NestedField::required(2, "bar", 
Type::Primitive(PrimitiveType::Int)).into(),
+                    NestedField::optional(3, "baz", 
Type::Primitive(PrimitiveType::Boolean)).into(),
+                ])
+                .build()
+                .unwrap(),
+        )
+    }
+
+    #[test]
+    fn test_bind_is_null() {
+        let schema = table_schema_simple();
+        let expr = Reference::new("foo").is_null();
+        let bound_expr = expr.bind(schema, true).unwrap();
+        assert_eq!(&format!("{bound_expr}"), "foo IS NULL");
+    }
+
+    #[test]
+    fn test_bind_is_null_required() {
+        let schema = table_schema_simple();
+        let expr = Reference::new("bar").is_null();
+        let bound_expr = expr.bind(schema, true).unwrap();
+        assert_eq!(&format!("{bound_expr}"), "False");
+    }
+
+    #[test]
+    fn test_bind_is_not_null() {
+        let schema = table_schema_simple();
+        let expr = Reference::new("foo").is_not_null();
+        let bound_expr = expr.bind(schema, true).unwrap();
+        assert_eq!(&format!("{bound_expr}"), "foo IS NOT NULL");
+    }
+
+    #[test]
+    fn test_bind_is_not_null_required() {
+        let schema = table_schema_simple();
+        let expr = Reference::new("bar").is_not_null();
+        let bound_expr = expr.bind(schema, true).unwrap();
+        assert_eq!(&format!("{bound_expr}"), "True");
+    }
+
+    #[test]
+    fn test_bind_less_than() {
+        let schema = table_schema_simple();
+        let expr = Reference::new("bar").less_than(Datum::int(10));
+        let bound_expr = expr.bind(schema, true).unwrap();
+        assert_eq!(&format!("{bound_expr}"), "bar < 10");
+    }
+
+    #[test]
+    fn test_bind_less_than_wrong_type() {
+        let schema = table_schema_simple();
+        let expr = Reference::new("bar").less_than(Datum::string("abcd"));
+        let bound_expr = expr.bind(schema, true);
+        assert!(bound_expr.is_err());
+    }
+
+    #[test]
+    fn test_bind_greater_than_or_eq() {
+        let schema = table_schema_simple();
+        let expr = 
Reference::new("bar").greater_than_or_equal_to(Datum::int(10));
+        let bound_expr = expr.bind(schema, true).unwrap();
+        assert_eq!(&format!("{bound_expr}"), "bar >= 10");
+    }
+
+    #[test]
+    fn test_bind_greater_than_or_eq_wrong_type() {
+        let schema = table_schema_simple();
+        let expr = 
Reference::new("bar").greater_than_or_equal_to(Datum::string("abcd"));
+        let bound_expr = expr.bind(schema, true);
+        assert!(bound_expr.is_err());
+    }
+
+    #[test]
+    fn test_bind_in() {
+        let schema = table_schema_simple();
+        let expr = Reference::new("bar").is_in([Datum::int(10), 
Datum::int(20)]);
+        let bound_expr = expr.bind(schema, true).unwrap();
+        assert_eq!(&format!("{bound_expr}"), "bar IN (20, 10)");
+    }
+
+    #[test]
+    fn test_bind_in_empty() {
+        let schema = table_schema_simple();
+        let expr = Reference::new("bar").is_in(vec![]);
+        let bound_expr = expr.bind(schema, true).unwrap();
+        assert_eq!(&format!("{bound_expr}"), "False");
+    }
+
+    #[test]
+    fn test_bind_in_one_literal() {
+        let schema = table_schema_simple();
+        let expr = Reference::new("bar").is_in(vec![Datum::int(10)]);
+        let bound_expr = expr.bind(schema, true).unwrap();
+        assert_eq!(&format!("{bound_expr}"), "bar = 10");
+    }
+
+    #[test]
+    fn test_bind_in_wrong_type() {
+        let schema = table_schema_simple();
+        let expr = Reference::new("bar").is_in(vec![Datum::int(10), 
Datum::string("abcd")]);
+        let bound_expr = expr.bind(schema, true);
+        assert!(bound_expr.is_err());
+    }
+
+    #[test]
+    fn test_bind_not_in() {
+        let schema = table_schema_simple();
+        let expr = Reference::new("bar").is_not_in([Datum::int(10), 
Datum::int(20)]);
+        let bound_expr = expr.bind(schema, true).unwrap();
+        assert_eq!(&format!("{bound_expr}"), "bar NOT IN (20, 10)");
+    }
+
+    #[test]
+    fn test_bind_not_in_empty() {
+        let schema = table_schema_simple();
+        let expr = Reference::new("bar").is_not_in(vec![]);
+        let bound_expr = expr.bind(schema, true).unwrap();
+        assert_eq!(&format!("{bound_expr}"), "True");
+    }
+
+    #[test]
+    fn test_bind_not_in_one_literal() {
+        let schema = table_schema_simple();
+        let expr = Reference::new("bar").is_not_in(vec![Datum::int(10)]);
+        let bound_expr = expr.bind(schema, true).unwrap();
+        assert_eq!(&format!("{bound_expr}"), "bar != 10");
+    }
+
+    #[test]
+    fn test_bind_not_in_wrong_type() {
+        let schema = table_schema_simple();
+        let expr = Reference::new("bar").is_not_in([Datum::int(10), 
Datum::string("abcd")]);
+        let bound_expr = expr.bind(schema, true);
+        assert!(bound_expr.is_err());
+    }
+
+    #[test]
+    fn test_bind_and() {
+        let schema = table_schema_simple();
+        let expr = Reference::new("bar")
+            .less_than(Datum::int(10))
+            .and(Reference::new("foo").is_null());
+        let bound_expr = expr.bind(schema, true).unwrap();
+        assert_eq!(&format!("{bound_expr}"), "(bar < 10) AND (foo IS NULL)");
+    }
+
+    #[test]
+    fn test_bind_and_always_false() {
+        let schema = table_schema_simple();
+        let expr = Reference::new("foo")
+            .less_than(Datum::string("abcd"))
+            .and(Reference::new("bar").is_null());
+        let bound_expr = expr.bind(schema, true).unwrap();
+        assert_eq!(&format!("{bound_expr}"), "False");
+    }
+
+    #[test]
+    fn test_bind_and_always_true() {
+        let schema = table_schema_simple();
+        let expr = Reference::new("foo")
+            .less_than(Datum::string("abcd"))
+            .and(Reference::new("bar").is_not_null());
+        let bound_expr = expr.bind(schema, true).unwrap();
+        assert_eq!(&format!("{bound_expr}"), r#"foo < "abcd""#);
+    }
+
+    #[test]
+    fn test_bind_or() {
+        let schema = table_schema_simple();
+        let expr = Reference::new("bar")
+            .less_than(Datum::int(10))
+            .or(Reference::new("foo").is_null());
+        let bound_expr = expr.bind(schema, true).unwrap();
+        assert_eq!(&format!("{bound_expr}"), "(bar < 10) OR (foo IS NULL)");
+    }
+
+    #[test]
+    fn test_bind_or_always_true() {
+        let schema = table_schema_simple();
+        let expr = Reference::new("foo")
+            .less_than(Datum::string("abcd"))
+            .or(Reference::new("bar").is_not_null());
+        let bound_expr = expr.bind(schema, true).unwrap();
+        assert_eq!(&format!("{bound_expr}"), "True");
+    }
+
+    #[test]
+    fn test_bind_or_always_false() {
+        let schema = table_schema_simple();
+        let expr = Reference::new("foo")
+            .less_than(Datum::string("abcd"))
+            .or(Reference::new("bar").is_null());
+        let bound_expr = expr.bind(schema, true).unwrap();
+        assert_eq!(&format!("{bound_expr}"), r#"foo < "abcd""#);
+    }
+
+    #[test]
+    fn test_bind_not() {
+        let schema = table_schema_simple();
+        let expr = !Reference::new("bar").less_than(Datum::int(10));
+        let bound_expr = expr.bind(schema, true).unwrap();
+        assert_eq!(&format!("{bound_expr}"), "NOT (bar < 10)");

Review Comment:
   `bar >= 10` if you use `negate()` :-)



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to