marvinlanhenke commented on code in PR #367:
URL: https://github.com/apache/iceberg-rust/pull/367#discussion_r1598017270


##########
crates/iceberg/src/expr/visitors/manifest_evaluator.rs:
##########
@@ -103,98 +106,245 @@ impl BoundPredicateVisitor for ManifestFilterVisitor<'_> 
{
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+
+        // contains_null encodes whether at least one partition value is null,
+        // lowerBound is null if all partition values are null
+        if self.are_all_null(field, &reference.field().field_type) {
+            ROWS_CANNOT_MATCH
+        } else {
+            ROWS_MIGHT_MATCH
+        }
     }
 
+    #[allow(clippy::bool_comparison)]
     fn is_nan(
         &mut self,
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        Ok(self
-            .field_summary_for_reference(reference)
-            .contains_nan
-            .is_some())
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if field.contains_nan.is_some_and(|x| x == false) {
+            return ROWS_CANNOT_MATCH;
+        }
+
+        if self.are_all_null(field, &reference.field().field_type) {
+            return ROWS_CANNOT_MATCH;
+        }
+
+        ROWS_MIGHT_MATCH
     }
 
+    #[allow(clippy::bool_comparison)]
     fn not_nan(
         &mut self,
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if field.contains_nan.is_some_and(|x| x == true)
+            && !field.contains_null
+            && field.lower_bound.is_none()
+        {
+            ROWS_CANNOT_MATCH
+        } else {
+            ROWS_MIGHT_MATCH
+        }
     }
 
     fn less_than(
         &mut self,
         reference: &BoundReference,
-        literal: &Datum,
+        datum: &Datum,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if let Some(Literal::Primitive(lower_bound)) = &field.lower_bound {
+            Ok(lower_bound < datum.literal())
+        } else {
+            ROWS_CANNOT_MATCH
+        }
     }
 
     fn less_than_or_eq(
         &mut self,
         reference: &BoundReference,
-        literal: &Datum,
+        datum: &Datum,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if let Some(Literal::Primitive(lower_bound)) = &field.lower_bound {
+            Ok(lower_bound <= datum.literal())
+        } else {
+            ROWS_CANNOT_MATCH
+        }
     }
 
     fn greater_than(
         &mut self,
         reference: &BoundReference,
-        literal: &Datum,
+        datum: &Datum,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if let Some(Literal::Primitive(upper_bound)) = &field.upper_bound {
+            Ok(upper_bound > datum.literal())
+        } else {
+            ROWS_CANNOT_MATCH
+        }
     }
 
     fn greater_than_or_eq(
         &mut self,
         reference: &BoundReference,
-        literal: &Datum,
+        datum: &Datum,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if let Some(Literal::Primitive(upper_bound)) = &field.upper_bound {
+            Ok(upper_bound >= datum.literal())
+        } else {
+            ROWS_CANNOT_MATCH
+        }
     }
 
     fn eq(
         &mut self,
         reference: &BoundReference,
-        literal: &Datum,
+        datum: &Datum,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        Ok(self.less_than_or_eq(reference, datum, _predicate)?
+            && self.greater_than_or_eq(reference, datum, _predicate)?)
     }
 
     fn not_eq(
         &mut self,
-        reference: &BoundReference,
-        literal: &Datum,
+        _reference: &BoundReference,
+        _datum: &Datum,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        // because the bounds are not necessarily a min or max value, this 
cannot be answered using
+        // them. notEq(col, X) with (X, Y) doesn't guarantee that X is a value 
in col.
+        ROWS_MIGHT_MATCH
     }
 
     fn starts_with(
         &mut self,
         reference: &BoundReference,
-        literal: &Datum,
+        datum: &Datum,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+
+        if field.lower_bound.is_none() || field.upper_bound.is_none() {
+            return ROWS_CANNOT_MATCH;
+        }
+
+        let PrimitiveLiteral::String(prefix) = datum.literal() else {
+            return Err(Error::new(
+                ErrorKind::Unexpected,
+                "Cannot perform starts_with on non-string value",
+            ));
+        };
+
+        let prefix_len = prefix.chars().count();
+
+        if let Some(lower_bound) = &field.lower_bound {

Review Comment:
   suggestion: extract into helper fn, since its used in multiple places?



##########
crates/iceberg/src/expr/visitors/manifest_evaluator.rs:
##########
@@ -103,98 +106,245 @@ impl BoundPredicateVisitor for ManifestFilterVisitor<'_> 
{
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+
+        // contains_null encodes whether at least one partition value is null,
+        // lowerBound is null if all partition values are null
+        if self.are_all_null(field, &reference.field().field_type) {

Review Comment:
   is the impl correct here? shouldn't we work with `lhs` and `rhs` and e.g. if 
both result are `true` we return ROWS_MIGHT_MATCH? 
https://github.com/apache/iceberg-python/blob/main/pyiceberg/expressions/visitors.py#L779



##########
crates/iceberg/src/expr/visitors/manifest_evaluator.rs:
##########
@@ -103,98 +106,245 @@ impl BoundPredicateVisitor for ManifestFilterVisitor<'_> 
{
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+
+        // contains_null encodes whether at least one partition value is null,
+        // lowerBound is null if all partition values are null
+        if self.are_all_null(field, &reference.field().field_type) {
+            ROWS_CANNOT_MATCH
+        } else {
+            ROWS_MIGHT_MATCH
+        }
     }
 
+    #[allow(clippy::bool_comparison)]
     fn is_nan(
         &mut self,
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        Ok(self
-            .field_summary_for_reference(reference)
-            .contains_nan
-            .is_some())
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if field.contains_nan.is_some_and(|x| x == false) {
+            return ROWS_CANNOT_MATCH;
+        }
+
+        if self.are_all_null(field, &reference.field().field_type) {
+            return ROWS_CANNOT_MATCH;
+        }
+
+        ROWS_MIGHT_MATCH
     }
 
+    #[allow(clippy::bool_comparison)]
     fn not_nan(
         &mut self,
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if field.contains_nan.is_some_and(|x| x == true)
+            && !field.contains_null
+            && field.lower_bound.is_none()
+        {
+            ROWS_CANNOT_MATCH
+        } else {
+            ROWS_MIGHT_MATCH
+        }
     }
 
     fn less_than(
         &mut self,
         reference: &BoundReference,
-        literal: &Datum,
+        datum: &Datum,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if let Some(Literal::Primitive(lower_bound)) = &field.lower_bound {
+            Ok(lower_bound < datum.literal())

Review Comment:
   if I'm not mistaken; please take a look at the other impl as well; since its 
mixed up there as well.



##########
crates/iceberg/src/expr/visitors/manifest_evaluator.rs:
##########
@@ -103,98 +106,245 @@ impl BoundPredicateVisitor for ManifestFilterVisitor<'_> 
{
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+
+        // contains_null encodes whether at least one partition value is null,
+        // lowerBound is null if all partition values are null
+        if self.are_all_null(field, &reference.field().field_type) {
+            ROWS_CANNOT_MATCH
+        } else {
+            ROWS_MIGHT_MATCH
+        }
     }
 
+    #[allow(clippy::bool_comparison)]
     fn is_nan(
         &mut self,
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        Ok(self
-            .field_summary_for_reference(reference)
-            .contains_nan
-            .is_some())
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if field.contains_nan.is_some_and(|x| x == false) {
+            return ROWS_CANNOT_MATCH;
+        }
+
+        if self.are_all_null(field, &reference.field().field_type) {
+            return ROWS_CANNOT_MATCH;
+        }
+
+        ROWS_MIGHT_MATCH
     }
 
+    #[allow(clippy::bool_comparison)]
     fn not_nan(
         &mut self,
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if field.contains_nan.is_some_and(|x| x == true)
+            && !field.contains_null
+            && field.lower_bound.is_none()
+        {
+            ROWS_CANNOT_MATCH
+        } else {
+            ROWS_MIGHT_MATCH
+        }
     }
 
     fn less_than(
         &mut self,
         reference: &BoundReference,
-        literal: &Datum,
+        datum: &Datum,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if let Some(Literal::Primitive(lower_bound)) = &field.lower_bound {
+            Ok(lower_bound < datum.literal())

Review Comment:
   I think this has to be the other way around?
   ```suggestion
               Ok(datum.literal() < lower_bound)
   ```



##########
crates/iceberg/src/expr/visitors/manifest_evaluator.rs:
##########
@@ -103,98 +106,245 @@ impl BoundPredicateVisitor for ManifestFilterVisitor<'_> 
{
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+
+        // contains_null encodes whether at least one partition value is null,
+        // lowerBound is null if all partition values are null
+        if self.are_all_null(field, &reference.field().field_type) {
+            ROWS_CANNOT_MATCH
+        } else {
+            ROWS_MIGHT_MATCH
+        }
     }
 
+    #[allow(clippy::bool_comparison)]
     fn is_nan(
         &mut self,
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        Ok(self
-            .field_summary_for_reference(reference)
-            .contains_nan
-            .is_some())
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if field.contains_nan.is_some_and(|x| x == false) {
+            return ROWS_CANNOT_MATCH;
+        }
+
+        if self.are_all_null(field, &reference.field().field_type) {
+            return ROWS_CANNOT_MATCH;
+        }
+
+        ROWS_MIGHT_MATCH
     }
 
+    #[allow(clippy::bool_comparison)]
     fn not_nan(
         &mut self,
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if field.contains_nan.is_some_and(|x| x == true)
+            && !field.contains_null
+            && field.lower_bound.is_none()
+        {
+            ROWS_CANNOT_MATCH

Review Comment:
   nit: maybe we can use an early return as well? would be consistent with the 
other implementations.



##########
crates/iceberg/src/expr/visitors/manifest_evaluator.rs:
##########
@@ -103,98 +106,245 @@ impl BoundPredicateVisitor for ManifestFilterVisitor<'_> 
{
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);

Review Comment:
   nit: I don't think we need the type annotation here?
   ```suggestion
           let field = self.field_summary_for_reference(reference);
   ```



##########
crates/iceberg/src/expr/visitors/manifest_evaluator.rs:
##########
@@ -103,98 +106,245 @@ impl BoundPredicateVisitor for ManifestFilterVisitor<'_> 
{
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+
+        // contains_null encodes whether at least one partition value is null,
+        // lowerBound is null if all partition values are null
+        if self.are_all_null(field, &reference.field().field_type) {
+            ROWS_CANNOT_MATCH
+        } else {
+            ROWS_MIGHT_MATCH
+        }
     }
 
+    #[allow(clippy::bool_comparison)]
     fn is_nan(
         &mut self,
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        Ok(self
-            .field_summary_for_reference(reference)
-            .contains_nan
-            .is_some())
+        let field: &FieldSummary = self.field_summary_for_reference(reference);

Review Comment:
   nit: we don't need the type annotation here?



##########
crates/iceberg/src/expr/visitors/manifest_evaluator.rs:
##########
@@ -103,98 +106,245 @@ impl BoundPredicateVisitor for ManifestFilterVisitor<'_> 
{
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+
+        // contains_null encodes whether at least one partition value is null,
+        // lowerBound is null if all partition values are null
+        if self.are_all_null(field, &reference.field().field_type) {
+            ROWS_CANNOT_MATCH
+        } else {
+            ROWS_MIGHT_MATCH
+        }
     }
 
+    #[allow(clippy::bool_comparison)]
     fn is_nan(
         &mut self,
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        Ok(self
-            .field_summary_for_reference(reference)
-            .contains_nan
-            .is_some())
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if field.contains_nan.is_some_and(|x| x == false) {
+            return ROWS_CANNOT_MATCH;
+        }
+
+        if self.are_all_null(field, &reference.field().field_type) {

Review Comment:
   isn't this check redundant? If the partition contains no NaN values, we 
don't need to check if all values are null. If all values are null it cannot 
contain any NaN values - but we already know that.



##########
crates/iceberg/src/expr/visitors/manifest_evaluator.rs:
##########
@@ -103,98 +106,245 @@ impl BoundPredicateVisitor for ManifestFilterVisitor<'_> 
{
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+
+        // contains_null encodes whether at least one partition value is null,
+        // lowerBound is null if all partition values are null
+        if self.are_all_null(field, &reference.field().field_type) {
+            ROWS_CANNOT_MATCH
+        } else {
+            ROWS_MIGHT_MATCH
+        }
     }
 
+    #[allow(clippy::bool_comparison)]
     fn is_nan(
         &mut self,
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        Ok(self
-            .field_summary_for_reference(reference)
-            .contains_nan
-            .is_some())
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if field.contains_nan.is_some_and(|x| x == false) {
+            return ROWS_CANNOT_MATCH;
+        }
+
+        if self.are_all_null(field, &reference.field().field_type) {
+            return ROWS_CANNOT_MATCH;
+        }
+
+        ROWS_MIGHT_MATCH
     }
 
+    #[allow(clippy::bool_comparison)]
     fn not_nan(
         &mut self,
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if field.contains_nan.is_some_and(|x| x == true)
+            && !field.contains_null
+            && field.lower_bound.is_none()
+        {
+            ROWS_CANNOT_MATCH
+        } else {
+            ROWS_MIGHT_MATCH
+        }
     }
 
     fn less_than(
         &mut self,
         reference: &BoundReference,
-        literal: &Datum,
+        datum: &Datum,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if let Some(Literal::Primitive(lower_bound)) = &field.lower_bound {
+            Ok(lower_bound < datum.literal())
+        } else {
+            ROWS_CANNOT_MATCH
+        }
     }
 
     fn less_than_or_eq(
         &mut self,
         reference: &BoundReference,
-        literal: &Datum,
+        datum: &Datum,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if let Some(Literal::Primitive(lower_bound)) = &field.lower_bound {
+            Ok(lower_bound <= datum.literal())
+        } else {
+            ROWS_CANNOT_MATCH
+        }
     }
 
     fn greater_than(
         &mut self,
         reference: &BoundReference,
-        literal: &Datum,
+        datum: &Datum,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if let Some(Literal::Primitive(upper_bound)) = &field.upper_bound {
+            Ok(upper_bound > datum.literal())
+        } else {
+            ROWS_CANNOT_MATCH
+        }
     }
 
     fn greater_than_or_eq(
         &mut self,
         reference: &BoundReference,
-        literal: &Datum,
+        datum: &Datum,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if let Some(Literal::Primitive(upper_bound)) = &field.upper_bound {
+            Ok(upper_bound >= datum.literal())
+        } else {
+            ROWS_CANNOT_MATCH
+        }
     }
 
     fn eq(
         &mut self,
         reference: &BoundReference,
-        literal: &Datum,
+        datum: &Datum,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        Ok(self.less_than_or_eq(reference, datum, _predicate)?

Review Comment:
   I think it's harder to understand if you put it that way? plus we're missing 
an early return 
https://github.com/apache/iceberg-python/blob/main/pyiceberg/expressions/visitors.py#L639-L641



##########
crates/iceberg/src/expr/visitors/manifest_evaluator.rs:
##########
@@ -103,98 +106,245 @@ impl BoundPredicateVisitor for ManifestFilterVisitor<'_> 
{
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+
+        // contains_null encodes whether at least one partition value is null,
+        // lowerBound is null if all partition values are null
+        if self.are_all_null(field, &reference.field().field_type) {
+            ROWS_CANNOT_MATCH
+        } else {
+            ROWS_MIGHT_MATCH
+        }
     }
 
+    #[allow(clippy::bool_comparison)]
     fn is_nan(
         &mut self,
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        Ok(self
-            .field_summary_for_reference(reference)
-            .contains_nan
-            .is_some())
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if field.contains_nan.is_some_and(|x| x == false) {
+            return ROWS_CANNOT_MATCH;
+        }
+
+        if self.are_all_null(field, &reference.field().field_type) {
+            return ROWS_CANNOT_MATCH;
+        }
+
+        ROWS_MIGHT_MATCH
     }
 
+    #[allow(clippy::bool_comparison)]
     fn not_nan(
         &mut self,
         reference: &BoundReference,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if field.contains_nan.is_some_and(|x| x == true)
+            && !field.contains_null
+            && field.lower_bound.is_none()
+        {
+            ROWS_CANNOT_MATCH
+        } else {
+            ROWS_MIGHT_MATCH
+        }
     }
 
     fn less_than(
         &mut self,
         reference: &BoundReference,
-        literal: &Datum,
+        datum: &Datum,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if let Some(Literal::Primitive(lower_bound)) = &field.lower_bound {
+            Ok(lower_bound < datum.literal())
+        } else {
+            ROWS_CANNOT_MATCH
+        }
     }
 
     fn less_than_or_eq(
         &mut self,
         reference: &BoundReference,
-        literal: &Datum,
+        datum: &Datum,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if let Some(Literal::Primitive(lower_bound)) = &field.lower_bound {
+            Ok(lower_bound <= datum.literal())
+        } else {
+            ROWS_CANNOT_MATCH
+        }
     }
 
     fn greater_than(
         &mut self,
         reference: &BoundReference,
-        literal: &Datum,
+        datum: &Datum,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if let Some(Literal::Primitive(upper_bound)) = &field.upper_bound {
+            Ok(upper_bound > datum.literal())
+        } else {
+            ROWS_CANNOT_MATCH
+        }
     }
 
     fn greater_than_or_eq(
         &mut self,
         reference: &BoundReference,
-        literal: &Datum,
+        datum: &Datum,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+        if let Some(Literal::Primitive(upper_bound)) = &field.upper_bound {
+            Ok(upper_bound >= datum.literal())
+        } else {
+            ROWS_CANNOT_MATCH
+        }
     }
 
     fn eq(
         &mut self,
         reference: &BoundReference,
-        literal: &Datum,
+        datum: &Datum,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        Ok(self.less_than_or_eq(reference, datum, _predicate)?
+            && self.greater_than_or_eq(reference, datum, _predicate)?)
     }
 
     fn not_eq(
         &mut self,
-        reference: &BoundReference,
-        literal: &Datum,
+        _reference: &BoundReference,
+        _datum: &Datum,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        // because the bounds are not necessarily a min or max value, this 
cannot be answered using
+        // them. notEq(col, X) with (X, Y) doesn't guarantee that X is a value 
in col.
+        ROWS_MIGHT_MATCH
     }
 
     fn starts_with(
         &mut self,
         reference: &BoundReference,
-        literal: &Datum,
+        datum: &Datum,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+
+        if field.lower_bound.is_none() || field.upper_bound.is_none() {
+            return ROWS_CANNOT_MATCH;
+        }
+
+        let PrimitiveLiteral::String(prefix) = datum.literal() else {
+            return Err(Error::new(
+                ErrorKind::Unexpected,
+                "Cannot perform starts_with on non-string value",
+            ));
+        };
+
+        let prefix_len = prefix.chars().count();
+
+        if let Some(lower_bound) = &field.lower_bound {
+            let Literal::Primitive(PrimitiveLiteral::String(lower_bound)) = 
lower_bound else {
+                return Err(Error::new(
+                    ErrorKind::Unexpected,
+                    "Cannot perform starts_with on non-string lower bound",
+                ));
+            };
+
+            let min_len = lower_bound.chars().count().min(prefix_len);
+            let truncated_lower_bound = 
lower_bound.chars().take(min_len).collect::<String>();
+            if prefix < &truncated_lower_bound {
+                return ROWS_CANNOT_MATCH;
+            }
+        }
+
+        if let Some(upper_bound) = &field.upper_bound {
+            let Literal::Primitive(PrimitiveLiteral::String(upper_bound)) = 
upper_bound else {
+                return Err(Error::new(
+                    ErrorKind::Unexpected,
+                    "Cannot perform starts_with on non-string upper bound",
+                ));
+            };
+
+            let min_len = upper_bound.chars().count().min(prefix_len);
+            let truncated_upper_bound = 
upper_bound.chars().take(min_len).collect::<String>();
+            if prefix > &truncated_upper_bound {
+                return ROWS_CANNOT_MATCH;
+            }
+        }
+
+        ROWS_MIGHT_MATCH
     }
 
     fn not_starts_with(
         &mut self,
         reference: &BoundReference,
-        literal: &Datum,
+        datum: &Datum,
         _predicate: &BoundPredicate,
     ) -> crate::Result<bool> {
-        todo!()
+        let field: &FieldSummary = self.field_summary_for_reference(reference);
+
+        if field.contains_null || field.lower_bound.is_none() || 
field.upper_bound.is_none() {
+            return ROWS_MIGHT_MATCH;
+        }
+
+        let PrimitiveLiteral::String(prefix) = datum.literal() else {
+            return Err(Error::new(
+                ErrorKind::Unexpected,
+                "Cannot perform not_starts_with on non-string value",
+            ));
+        };
+
+        let prefix_len = prefix.chars().count();
+
+        // not_starts_with will match unless all values must start with the 
prefix. This happens when
+        // the lower and upper bounds both start with the prefix.
+        if let Some(lower_bound) = &field.lower_bound {
+            let Literal::Primitive(PrimitiveLiteral::String(lower_bound)) = 
lower_bound else {
+                return Err(Error::new(
+                    ErrorKind::Unexpected,
+                    "Cannot perform not_starts_with on non-string lower bound",
+                ));
+            };
+
+            // if lower is shorter than the prefix then lower doesn't start 
with the prefix
+            if prefix_len > lower_bound.chars().count() {
+                return ROWS_MIGHT_MATCH;
+            }
+
+            let truncated_lower_bound = 
lower_bound.chars().take(prefix_len).collect::<String>();
+            if prefix == &truncated_lower_bound {
+                if let Some(upper_bound) = &field.upper_bound {
+                    let 
Literal::Primitive(PrimitiveLiteral::String(upper_bound)) = upper_bound
+                    else {
+                        return Err(Error::new(
+                            ErrorKind::Unexpected,
+                            "Cannot perform not_starts_with on non-string 
upper bound",
+                        ));
+                    };
+
+                    // if upper is shorter than the prefix then upper can't 
start with the prefix
+                    if prefix_len > upper_bound.chars().count() {
+                        return ROWS_MIGHT_MATCH;
+                    }
+
+                    let truncated_upper_bound =

Review Comment:
   I think we can avoid the extra String allocation by using `char_indices()` 
to get the prefix_len and then use a slice for comparison `let 
truncated_upper_bound = &upper_bound[..prefix_len];` // haven't tested it though



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