You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "jonathanc-n (via GitHub)" <gi...@apache.org> on 2025/02/12 04:39:28 UTC
[PR] feat: Add `StrictMetricsEvaluator` [iceberg-rust]
jonathanc-n opened a new pull request, #963:
URL: https://github.com/apache/iceberg-rust/pull/963
Added `StrictMetricsEvaluator`.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat: Add `StrictMetricsEvaluator` [iceberg-rust]
Posted by "Fokko (via GitHub)" <gi...@apache.org>.
Fokko commented on code in PR #963:
URL: https://github.com/apache/iceberg-rust/pull/963#discussion_r1954322029
##########
crates/iceberg/src/expr/visitors/strict_metrics_evaluator.rs:
##########
@@ -0,0 +1,1854 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use fnv::FnvHashSet;
+
+use crate::expr::visitors::bound_predicate_visitor::{visit, BoundPredicateVisitor};
+use crate::expr::{BoundPredicate, BoundReference};
+use crate::spec::{DataFile, Datum, Schema};
+use crate::Result;
+
+#[allow(dead_code)]
+const ROWS_MUST_MATCH: Result<bool> = Ok(true);
+#[allow(dead_code)]
+const ROWS_MIGHT_NOT_MATCH: Result<bool> = Ok(false);
+
+#[allow(dead_code)]
+pub(crate) struct StrictMetricsEvaluator<'a> {
+ data_file: &'a DataFile,
+ schema: Schema,
+}
+
+impl<'a> StrictMetricsEvaluator<'a> {
+ #[allow(dead_code)]
+ fn new(data_file: &'a DataFile, schema: Schema) -> Self {
+ StrictMetricsEvaluator { data_file, schema }
+ }
+
+ /// Evaluate this `StrictMetricsEvaluator`'s filter predicate against the
+ /// provided [`DataFile`]'s metrics. Used by [`TableScan`] to
+ /// see if this `DataFile` contains data that could match
+ /// the scan's filter.
+ #[allow(dead_code)]
+ pub(crate) fn eval(
+ filter: &'a BoundPredicate,
+ data_file: &'a DataFile,
+ schema: Schema,
+ ) -> crate::Result<bool> {
+ if data_file.record_count == 0 {
+ return ROWS_MUST_MATCH;
+ }
+
+ let mut evaluator = Self::new(data_file, schema);
+ visit(&mut evaluator, filter)
+ }
+
+ fn nan_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.nan_value_counts.get(&field_id)
+ }
+
+ fn null_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.null_value_counts.get(&field_id)
+ }
+
+ fn value_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.value_counts.get(&field_id)
+ }
+
+ fn lower_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.lower_bounds.get(&field_id)
+ }
+
+ fn upper_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.upper_bounds.get(&field_id)
+ }
+
+ fn contains_nans_only(&self, field_id: i32) -> bool {
+ let nan_count = self.nan_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ nan_count.is_some() && nan_count == value_count
+ }
+
+ fn contains_nulls_only(&self, field_id: i32) -> bool {
+ let null_count = self.null_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ null_count.is_some() && null_count == value_count
+ }
+
+ fn may_contain_null(&self, field_id: i32) -> bool {
+ if let Some(&null_count) = self.null_count(field_id) {
+ null_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn may_contain_nan(&self, field_id: i32) -> bool {
+ if let Some(&nan_count) = self.nan_count(field_id) {
+ nan_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn visit_inequality(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ cmp_fn: fn(&Datum, &Datum) -> bool,
+ use_lower_bound: bool,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if self.contains_nulls_only(field_id) || self.contains_nans_only(field_id) {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ if datum.is_nan() {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ let bound = if use_lower_bound {
+ self.lower_bound(field_id)
+ } else {
+ self.upper_bound(field_id)
+ };
+
+ if let Some(bound) = bound {
+ if cmp_fn(bound, datum) {
+ return ROWS_MUST_MATCH;
+ }
+
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ ROWS_MIGHT_NOT_MATCH
+ }
+}
+
+impl BoundPredicateVisitor for StrictMetricsEvaluator<'_> {
+ type T = bool;
+
+ fn always_true(&mut self) -> crate::Result<bool> {
+ ROWS_MUST_MATCH
+ }
+
+ fn always_false(&mut self) -> crate::Result<bool> {
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn and(&mut self, lhs: bool, rhs: bool) -> crate::Result<bool> {
+ Ok(lhs && rhs)
+ }
+
+ fn or(&mut self, lhs: bool, rhs: bool) -> crate::Result<bool> {
+ Ok(lhs || rhs)
+ }
+
+ fn not(&mut self, inner: bool) -> crate::Result<bool> {
+ Ok(!inner)
Review Comment:
We want to throw an error here, since the `NOT` should be rewritten: https://github.com/apache/iceberg-python/blob/6d1c30c716333a25db975820d5ddbef4958c665b/pyiceberg/expressions/visitors.py#L1111-L1112
##########
crates/iceberg/src/expr/visitors/strict_metrics_evaluator.rs:
##########
@@ -0,0 +1,1854 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use fnv::FnvHashSet;
+
+use crate::expr::visitors::bound_predicate_visitor::{visit, BoundPredicateVisitor};
+use crate::expr::{BoundPredicate, BoundReference};
+use crate::spec::{DataFile, Datum, Schema};
+use crate::Result;
+
+#[allow(dead_code)]
+const ROWS_MUST_MATCH: Result<bool> = Ok(true);
+#[allow(dead_code)]
+const ROWS_MIGHT_NOT_MATCH: Result<bool> = Ok(false);
+
+#[allow(dead_code)]
+pub(crate) struct StrictMetricsEvaluator<'a> {
+ data_file: &'a DataFile,
+ schema: Schema,
+}
+
+impl<'a> StrictMetricsEvaluator<'a> {
+ #[allow(dead_code)]
+ fn new(data_file: &'a DataFile, schema: Schema) -> Self {
+ StrictMetricsEvaluator { data_file, schema }
+ }
+
+ /// Evaluate this `StrictMetricsEvaluator`'s filter predicate against the
+ /// provided [`DataFile`]'s metrics. Used by [`TableScan`] to
+ /// see if this `DataFile` contains data that could match
+ /// the scan's filter.
+ #[allow(dead_code)]
+ pub(crate) fn eval(
+ filter: &'a BoundPredicate,
+ data_file: &'a DataFile,
+ schema: Schema,
+ ) -> crate::Result<bool> {
+ if data_file.record_count == 0 {
+ return ROWS_MUST_MATCH;
+ }
+
+ let mut evaluator = Self::new(data_file, schema);
Review Comment:
Still learning rust, why is this one mutable?
##########
crates/iceberg/src/expr/visitors/strict_metrics_evaluator.rs:
##########
@@ -0,0 +1,1854 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use fnv::FnvHashSet;
+
+use crate::expr::visitors::bound_predicate_visitor::{visit, BoundPredicateVisitor};
+use crate::expr::{BoundPredicate, BoundReference};
+use crate::spec::{DataFile, Datum, Schema};
+use crate::Result;
+
+#[allow(dead_code)]
+const ROWS_MUST_MATCH: Result<bool> = Ok(true);
+#[allow(dead_code)]
+const ROWS_MIGHT_NOT_MATCH: Result<bool> = Ok(false);
+
+#[allow(dead_code)]
+pub(crate) struct StrictMetricsEvaluator<'a> {
+ data_file: &'a DataFile,
+ schema: Schema,
+}
+
+impl<'a> StrictMetricsEvaluator<'a> {
+ #[allow(dead_code)]
+ fn new(data_file: &'a DataFile, schema: Schema) -> Self {
+ StrictMetricsEvaluator { data_file, schema }
+ }
+
+ /// Evaluate this `StrictMetricsEvaluator`'s filter predicate against the
+ /// provided [`DataFile`]'s metrics. Used by [`TableScan`] to
+ /// see if this `DataFile` contains data that could match
+ /// the scan's filter.
+ #[allow(dead_code)]
+ pub(crate) fn eval(
+ filter: &'a BoundPredicate,
+ data_file: &'a DataFile,
+ schema: Schema,
Review Comment:
We don't need the schema AFAIK since already pass in a bound predicate.
##########
crates/iceberg/src/expr/visitors/strict_metrics_evaluator.rs:
##########
@@ -0,0 +1,1854 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use fnv::FnvHashSet;
+
+use crate::expr::visitors::bound_predicate_visitor::{visit, BoundPredicateVisitor};
+use crate::expr::{BoundPredicate, BoundReference};
+use crate::spec::{DataFile, Datum, Schema};
+use crate::Result;
+
+#[allow(dead_code)]
+const ROWS_MUST_MATCH: Result<bool> = Ok(true);
+#[allow(dead_code)]
+const ROWS_MIGHT_NOT_MATCH: Result<bool> = Ok(false);
+
+#[allow(dead_code)]
+pub(crate) struct StrictMetricsEvaluator<'a> {
+ data_file: &'a DataFile,
+ schema: Schema,
+}
+
+impl<'a> StrictMetricsEvaluator<'a> {
+ #[allow(dead_code)]
+ fn new(data_file: &'a DataFile, schema: Schema) -> Self {
+ StrictMetricsEvaluator { data_file, schema }
+ }
+
+ /// Evaluate this `StrictMetricsEvaluator`'s filter predicate against the
+ /// provided [`DataFile`]'s metrics. Used by [`TableScan`] to
+ /// see if this `DataFile` contains data that could match
+ /// the scan's filter.
+ #[allow(dead_code)]
+ pub(crate) fn eval(
+ filter: &'a BoundPredicate,
+ data_file: &'a DataFile,
+ schema: Schema,
+ ) -> crate::Result<bool> {
+ if data_file.record_count == 0 {
+ return ROWS_MUST_MATCH;
+ }
+
+ let mut evaluator = Self::new(data_file, schema);
+ visit(&mut evaluator, filter)
+ }
+
+ fn nan_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.nan_value_counts.get(&field_id)
+ }
+
+ fn null_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.null_value_counts.get(&field_id)
+ }
+
+ fn value_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.value_counts.get(&field_id)
+ }
+
+ fn lower_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.lower_bounds.get(&field_id)
+ }
+
+ fn upper_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.upper_bounds.get(&field_id)
+ }
+
+ fn contains_nans_only(&self, field_id: i32) -> bool {
+ let nan_count = self.nan_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ nan_count.is_some() && nan_count == value_count
+ }
+
+ fn contains_nulls_only(&self, field_id: i32) -> bool {
+ let null_count = self.null_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ null_count.is_some() && null_count == value_count
+ }
+
+ fn may_contain_null(&self, field_id: i32) -> bool {
+ if let Some(&null_count) = self.null_count(field_id) {
+ null_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn may_contain_nan(&self, field_id: i32) -> bool {
+ if let Some(&nan_count) = self.nan_count(field_id) {
+ nan_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn visit_inequality(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ cmp_fn: fn(&Datum, &Datum) -> bool,
+ use_lower_bound: bool,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if self.contains_nulls_only(field_id) || self.contains_nans_only(field_id) {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ if datum.is_nan() {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ let bound = if use_lower_bound {
+ self.lower_bound(field_id)
+ } else {
+ self.upper_bound(field_id)
+ };
+
+ if let Some(bound) = bound {
+ if cmp_fn(bound, datum) {
+ return ROWS_MUST_MATCH;
+ }
+
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ ROWS_MIGHT_NOT_MATCH
+ }
+}
+
+impl BoundPredicateVisitor for StrictMetricsEvaluator<'_> {
+ type T = bool;
+
+ fn always_true(&mut self) -> crate::Result<bool> {
+ ROWS_MUST_MATCH
+ }
+
+ fn always_false(&mut self) -> crate::Result<bool> {
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn and(&mut self, lhs: bool, rhs: bool) -> crate::Result<bool> {
+ Ok(lhs && rhs)
+ }
+
+ fn or(&mut self, lhs: bool, rhs: bool) -> crate::Result<bool> {
+ Ok(lhs || rhs)
+ }
+
+ fn not(&mut self, inner: bool) -> crate::Result<bool> {
+ Ok(!inner)
+ }
+
+ fn is_null(
+ &mut self,
+ reference: &BoundReference,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if self.contains_nulls_only(field_id) {
+ return ROWS_MUST_MATCH;
+ }
+
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn not_null(
+ &mut self,
+ reference: &BoundReference,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if let Some(&count) = self.null_count(field_id) {
+ if count == 0 {
+ return ROWS_MUST_MATCH;
+ } else {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+ }
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn is_nan(
+ &mut self,
+ reference: &BoundReference,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ let contains_only = self.contains_nans_only(field_id);
+
+ if contains_only {
+ return ROWS_MUST_MATCH;
+ }
+
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn not_nan(
+ &mut self,
+ reference: &BoundReference,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if let Some(&nan_count) = self.nan_count(field_id) {
+ if nan_count == 0 {
+ return ROWS_MUST_MATCH;
+ }
+ }
+
+ if self.contains_nulls_only(field_id) {
+ return ROWS_MUST_MATCH;
+ }
+
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn less_than(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ self.visit_inequality(reference, datum, PartialOrd::lt, false)
+ }
+
+ fn less_than_or_eq(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ self.visit_inequality(reference, datum, PartialOrd::le, false)
+ }
+
+ fn greater_than(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ self.visit_inequality(reference, datum, PartialOrd::gt, true)
+ }
+
+ fn greater_than_or_eq(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ self.visit_inequality(reference, datum, PartialOrd::ge, true)
+ }
+
+ fn eq(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if self.may_contain_null(field_id) || self.may_contain_nan(field_id) {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ if let (Some(lower), Some(upper)) = (self.lower_bound(field_id), self.upper_bound(field_id))
+ {
+ // For an equality predicate to hold strictly, we must have:
+ // lower == literal.value == upper.
+ if lower.literal() != datum.literal() || upper.literal() != datum.literal() {
+ return ROWS_MIGHT_NOT_MATCH;
+ } else {
+ return ROWS_MUST_MATCH;
+ }
Review Comment:
Aligns the comparison with the comment :)
```suggestion
// For an equality predicate to hold strictly, we must have:
// lower == literal.value == upper.
if lower.literal() == datum.literal() && upper.literal() == datum.literal() {
return ROWS_MUST_MATCH;
} else {
return ROWS_MIGHT_NOT_MATCH;
}
```
##########
crates/iceberg/src/expr/visitors/strict_metrics_evaluator.rs:
##########
@@ -0,0 +1,1854 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use fnv::FnvHashSet;
+
+use crate::expr::visitors::bound_predicate_visitor::{visit, BoundPredicateVisitor};
+use crate::expr::{BoundPredicate, BoundReference};
+use crate::spec::{DataFile, Datum, Schema};
+use crate::Result;
+
+#[allow(dead_code)]
+const ROWS_MUST_MATCH: Result<bool> = Ok(true);
+#[allow(dead_code)]
+const ROWS_MIGHT_NOT_MATCH: Result<bool> = Ok(false);
+
+#[allow(dead_code)]
+pub(crate) struct StrictMetricsEvaluator<'a> {
+ data_file: &'a DataFile,
+ schema: Schema,
+}
+
+impl<'a> StrictMetricsEvaluator<'a> {
+ #[allow(dead_code)]
+ fn new(data_file: &'a DataFile, schema: Schema) -> Self {
+ StrictMetricsEvaluator { data_file, schema }
+ }
+
+ /// Evaluate this `StrictMetricsEvaluator`'s filter predicate against the
+ /// provided [`DataFile`]'s metrics. Used by [`TableScan`] to
+ /// see if this `DataFile` contains data that could match
+ /// the scan's filter.
+ #[allow(dead_code)]
+ pub(crate) fn eval(
+ filter: &'a BoundPredicate,
+ data_file: &'a DataFile,
+ schema: Schema,
+ ) -> crate::Result<bool> {
+ if data_file.record_count == 0 {
+ return ROWS_MUST_MATCH;
+ }
+
+ let mut evaluator = Self::new(data_file, schema);
+ visit(&mut evaluator, filter)
+ }
+
+ fn nan_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.nan_value_counts.get(&field_id)
+ }
+
+ fn null_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.null_value_counts.get(&field_id)
+ }
+
+ fn value_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.value_counts.get(&field_id)
+ }
+
+ fn lower_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.lower_bounds.get(&field_id)
+ }
+
+ fn upper_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.upper_bounds.get(&field_id)
+ }
+
+ fn contains_nans_only(&self, field_id: i32) -> bool {
+ let nan_count = self.nan_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ nan_count.is_some() && nan_count == value_count
+ }
+
+ fn contains_nulls_only(&self, field_id: i32) -> bool {
+ let null_count = self.null_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ null_count.is_some() && null_count == value_count
+ }
+
+ fn may_contain_null(&self, field_id: i32) -> bool {
+ if let Some(&null_count) = self.null_count(field_id) {
+ null_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn may_contain_nan(&self, field_id: i32) -> bool {
+ if let Some(&nan_count) = self.nan_count(field_id) {
+ nan_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn visit_inequality(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ cmp_fn: fn(&Datum, &Datum) -> bool,
+ use_lower_bound: bool,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if self.contains_nulls_only(field_id) || self.contains_nans_only(field_id) {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ if datum.is_nan() {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
Review Comment:
Ah, I see, this comes from https://github.com/apache/iceberg/blob/68189d28e973e0a14626869ddfb4cb572d5ef2ef/api/src/main/java/org/apache/iceberg/expressions/StrictMetricsEvaluator.java#L259-L262
##########
crates/iceberg/src/expr/visitors/strict_metrics_evaluator.rs:
##########
@@ -0,0 +1,1854 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use fnv::FnvHashSet;
+
+use crate::expr::visitors::bound_predicate_visitor::{visit, BoundPredicateVisitor};
+use crate::expr::{BoundPredicate, BoundReference};
+use crate::spec::{DataFile, Datum, Schema};
+use crate::Result;
+
+#[allow(dead_code)]
+const ROWS_MUST_MATCH: Result<bool> = Ok(true);
+#[allow(dead_code)]
+const ROWS_MIGHT_NOT_MATCH: Result<bool> = Ok(false);
+
+#[allow(dead_code)]
+pub(crate) struct StrictMetricsEvaluator<'a> {
+ data_file: &'a DataFile,
+ schema: Schema,
+}
+
+impl<'a> StrictMetricsEvaluator<'a> {
+ #[allow(dead_code)]
+ fn new(data_file: &'a DataFile, schema: Schema) -> Self {
+ StrictMetricsEvaluator { data_file, schema }
+ }
+
+ /// Evaluate this `StrictMetricsEvaluator`'s filter predicate against the
+ /// provided [`DataFile`]'s metrics. Used by [`TableScan`] to
+ /// see if this `DataFile` contains data that could match
+ /// the scan's filter.
+ #[allow(dead_code)]
+ pub(crate) fn eval(
+ filter: &'a BoundPredicate,
+ data_file: &'a DataFile,
+ schema: Schema,
+ ) -> crate::Result<bool> {
+ if data_file.record_count == 0 {
+ return ROWS_MUST_MATCH;
+ }
+
+ let mut evaluator = Self::new(data_file, schema);
+ visit(&mut evaluator, filter)
+ }
+
+ fn nan_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.nan_value_counts.get(&field_id)
+ }
+
+ fn null_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.null_value_counts.get(&field_id)
+ }
+
+ fn value_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.value_counts.get(&field_id)
+ }
+
+ fn lower_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.lower_bounds.get(&field_id)
+ }
+
+ fn upper_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.upper_bounds.get(&field_id)
+ }
+
+ fn contains_nans_only(&self, field_id: i32) -> bool {
+ let nan_count = self.nan_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ nan_count.is_some() && nan_count == value_count
+ }
+
+ fn contains_nulls_only(&self, field_id: i32) -> bool {
+ let null_count = self.null_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ null_count.is_some() && null_count == value_count
+ }
+
+ fn may_contain_null(&self, field_id: i32) -> bool {
+ if let Some(&null_count) = self.null_count(field_id) {
+ null_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn may_contain_nan(&self, field_id: i32) -> bool {
+ if let Some(&nan_count) = self.nan_count(field_id) {
+ nan_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn visit_inequality(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ cmp_fn: fn(&Datum, &Datum) -> bool,
+ use_lower_bound: bool,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if self.contains_nulls_only(field_id) || self.contains_nans_only(field_id) {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ if datum.is_nan() {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ let bound = if use_lower_bound {
+ self.lower_bound(field_id)
+ } else {
+ self.upper_bound(field_id)
+ };
+
+ if let Some(bound) = bound {
+ if cmp_fn(bound, datum) {
+ return ROWS_MUST_MATCH;
+ }
+
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ ROWS_MIGHT_NOT_MATCH
+ }
+}
+
+impl BoundPredicateVisitor for StrictMetricsEvaluator<'_> {
+ type T = bool;
+
+ fn always_true(&mut self) -> crate::Result<bool> {
+ ROWS_MUST_MATCH
+ }
+
+ fn always_false(&mut self) -> crate::Result<bool> {
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn and(&mut self, lhs: bool, rhs: bool) -> crate::Result<bool> {
+ Ok(lhs && rhs)
+ }
+
+ fn or(&mut self, lhs: bool, rhs: bool) -> crate::Result<bool> {
+ Ok(lhs || rhs)
+ }
+
+ fn not(&mut self, inner: bool) -> crate::Result<bool> {
+ Ok(!inner)
+ }
+
+ fn is_null(
+ &mut self,
+ reference: &BoundReference,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if self.contains_nulls_only(field_id) {
+ return ROWS_MUST_MATCH;
+ }
+
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn not_null(
+ &mut self,
+ reference: &BoundReference,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if let Some(&count) = self.null_count(field_id) {
+ if count == 0 {
+ return ROWS_MUST_MATCH;
+ } else {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+ }
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn is_nan(
+ &mut self,
+ reference: &BoundReference,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ let contains_only = self.contains_nans_only(field_id);
+
+ if contains_only {
+ return ROWS_MUST_MATCH;
+ }
+
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn not_nan(
+ &mut self,
+ reference: &BoundReference,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if let Some(&nan_count) = self.nan_count(field_id) {
+ if nan_count == 0 {
+ return ROWS_MUST_MATCH;
+ }
+ }
+
+ if self.contains_nulls_only(field_id) {
+ return ROWS_MUST_MATCH;
+ }
+
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn less_than(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ self.visit_inequality(reference, datum, PartialOrd::lt, false)
+ }
+
+ fn less_than_or_eq(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ self.visit_inequality(reference, datum, PartialOrd::le, false)
+ }
+
+ fn greater_than(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ self.visit_inequality(reference, datum, PartialOrd::gt, true)
+ }
+
+ fn greater_than_or_eq(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ self.visit_inequality(reference, datum, PartialOrd::ge, true)
+ }
+
+ fn eq(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if self.may_contain_null(field_id) || self.may_contain_nan(field_id) {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ if let (Some(lower), Some(upper)) = (self.lower_bound(field_id), self.upper_bound(field_id))
+ {
+ // For an equality predicate to hold strictly, we must have:
+ // lower == literal.value == upper.
+ if lower.literal() != datum.literal() || upper.literal() != datum.literal() {
+ return ROWS_MIGHT_NOT_MATCH;
+ } else {
+ return ROWS_MUST_MATCH;
+ }
+ }
+
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn not_eq(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if self.may_contain_null(field_id) || self.may_contain_nan(field_id) {
+ return ROWS_MUST_MATCH;
+ }
Review Comment:
```suggestion
if self.contains_nulls_only(field_id) || self.contains_nans_only(field_id) {
return ROWS_MUST_MATCH;
}
```
https://github.com/apache/iceberg/blob/68189d28e973e0a14626869ddfb4cb572d5ef2ef/api/src/main/java/org/apache/iceberg/expressions/StrictMetricsEvaluator.java#L346-L348
##########
crates/iceberg/src/expr/visitors/strict_metrics_evaluator.rs:
##########
@@ -0,0 +1,1854 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use fnv::FnvHashSet;
+
+use crate::expr::visitors::bound_predicate_visitor::{visit, BoundPredicateVisitor};
+use crate::expr::{BoundPredicate, BoundReference};
+use crate::spec::{DataFile, Datum, Schema};
+use crate::Result;
+
+#[allow(dead_code)]
+const ROWS_MUST_MATCH: Result<bool> = Ok(true);
+#[allow(dead_code)]
+const ROWS_MIGHT_NOT_MATCH: Result<bool> = Ok(false);
+
+#[allow(dead_code)]
+pub(crate) struct StrictMetricsEvaluator<'a> {
+ data_file: &'a DataFile,
+ schema: Schema,
+}
+
+impl<'a> StrictMetricsEvaluator<'a> {
+ #[allow(dead_code)]
+ fn new(data_file: &'a DataFile, schema: Schema) -> Self {
+ StrictMetricsEvaluator { data_file, schema }
+ }
+
+ /// Evaluate this `StrictMetricsEvaluator`'s filter predicate against the
+ /// provided [`DataFile`]'s metrics. Used by [`TableScan`] to
+ /// see if this `DataFile` contains data that could match
+ /// the scan's filter.
+ #[allow(dead_code)]
+ pub(crate) fn eval(
+ filter: &'a BoundPredicate,
+ data_file: &'a DataFile,
+ schema: Schema,
+ ) -> crate::Result<bool> {
+ if data_file.record_count == 0 {
+ return ROWS_MUST_MATCH;
+ }
+
+ let mut evaluator = Self::new(data_file, schema);
+ visit(&mut evaluator, filter)
+ }
+
+ fn nan_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.nan_value_counts.get(&field_id)
+ }
+
+ fn null_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.null_value_counts.get(&field_id)
+ }
+
+ fn value_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.value_counts.get(&field_id)
+ }
+
+ fn lower_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.lower_bounds.get(&field_id)
+ }
+
+ fn upper_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.upper_bounds.get(&field_id)
+ }
+
+ fn contains_nans_only(&self, field_id: i32) -> bool {
+ let nan_count = self.nan_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ nan_count.is_some() && nan_count == value_count
+ }
+
+ fn contains_nulls_only(&self, field_id: i32) -> bool {
+ let null_count = self.null_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ null_count.is_some() && null_count == value_count
+ }
+
+ fn may_contain_null(&self, field_id: i32) -> bool {
+ if let Some(&null_count) = self.null_count(field_id) {
+ null_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn may_contain_nan(&self, field_id: i32) -> bool {
+ if let Some(&nan_count) = self.nan_count(field_id) {
+ nan_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn visit_inequality(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ cmp_fn: fn(&Datum, &Datum) -> bool,
+ use_lower_bound: bool,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if self.contains_nulls_only(field_id) || self.contains_nans_only(field_id) {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ if datum.is_nan() {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
Review Comment:
I see that we only apply this on the lower bound in Java, should we do the same here?
##########
crates/iceberg/src/expr/visitors/strict_metrics_evaluator.rs:
##########
@@ -0,0 +1,1854 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use fnv::FnvHashSet;
+
+use crate::expr::visitors::bound_predicate_visitor::{visit, BoundPredicateVisitor};
+use crate::expr::{BoundPredicate, BoundReference};
+use crate::spec::{DataFile, Datum, Schema};
+use crate::Result;
+
+#[allow(dead_code)]
+const ROWS_MUST_MATCH: Result<bool> = Ok(true);
+#[allow(dead_code)]
+const ROWS_MIGHT_NOT_MATCH: Result<bool> = Ok(false);
+
+#[allow(dead_code)]
+pub(crate) struct StrictMetricsEvaluator<'a> {
+ data_file: &'a DataFile,
+ schema: Schema,
+}
+
+impl<'a> StrictMetricsEvaluator<'a> {
+ #[allow(dead_code)]
+ fn new(data_file: &'a DataFile, schema: Schema) -> Self {
+ StrictMetricsEvaluator { data_file, schema }
+ }
+
+ /// Evaluate this `StrictMetricsEvaluator`'s filter predicate against the
+ /// provided [`DataFile`]'s metrics. Used by [`TableScan`] to
+ /// see if this `DataFile` contains data that could match
+ /// the scan's filter.
+ #[allow(dead_code)]
+ pub(crate) fn eval(
+ filter: &'a BoundPredicate,
+ data_file: &'a DataFile,
+ schema: Schema,
+ ) -> crate::Result<bool> {
+ if data_file.record_count == 0 {
+ return ROWS_MUST_MATCH;
+ }
+
+ let mut evaluator = Self::new(data_file, schema);
+ visit(&mut evaluator, filter)
+ }
+
+ fn nan_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.nan_value_counts.get(&field_id)
+ }
+
+ fn null_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.null_value_counts.get(&field_id)
+ }
+
+ fn value_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.value_counts.get(&field_id)
+ }
+
+ fn lower_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.lower_bounds.get(&field_id)
+ }
+
+ fn upper_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.upper_bounds.get(&field_id)
+ }
+
+ fn contains_nans_only(&self, field_id: i32) -> bool {
+ let nan_count = self.nan_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ nan_count.is_some() && nan_count == value_count
+ }
+
+ fn contains_nulls_only(&self, field_id: i32) -> bool {
+ let null_count = self.null_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ null_count.is_some() && null_count == value_count
+ }
+
+ fn may_contain_null(&self, field_id: i32) -> bool {
+ if let Some(&null_count) = self.null_count(field_id) {
+ null_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn may_contain_nan(&self, field_id: i32) -> bool {
+ if let Some(&nan_count) = self.nan_count(field_id) {
+ nan_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn visit_inequality(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ cmp_fn: fn(&Datum, &Datum) -> bool,
+ use_lower_bound: bool,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if self.contains_nulls_only(field_id) || self.contains_nans_only(field_id) {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
Review Comment:
```suggestion
if self. may_contain_null(field_id) || self. may_contain_nan(field_id) {
return ROWS_MIGHT_NOT_MATCH;
}
```
https://github.com/apache/iceberg/blob/68189d28e973e0a14626869ddfb4cb572d5ef2ef/api/src/main/java/org/apache/iceberg/expressions/StrictMetricsEvaluator.java#L204-L206
##########
crates/iceberg/src/expr/visitors/strict_metrics_evaluator.rs:
##########
@@ -0,0 +1,1854 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use fnv::FnvHashSet;
+
+use crate::expr::visitors::bound_predicate_visitor::{visit, BoundPredicateVisitor};
+use crate::expr::{BoundPredicate, BoundReference};
+use crate::spec::{DataFile, Datum, Schema};
+use crate::Result;
+
+#[allow(dead_code)]
+const ROWS_MUST_MATCH: Result<bool> = Ok(true);
+#[allow(dead_code)]
+const ROWS_MIGHT_NOT_MATCH: Result<bool> = Ok(false);
+
+#[allow(dead_code)]
+pub(crate) struct StrictMetricsEvaluator<'a> {
+ data_file: &'a DataFile,
+ schema: Schema,
+}
+
+impl<'a> StrictMetricsEvaluator<'a> {
+ #[allow(dead_code)]
+ fn new(data_file: &'a DataFile, schema: Schema) -> Self {
+ StrictMetricsEvaluator { data_file, schema }
+ }
+
+ /// Evaluate this `StrictMetricsEvaluator`'s filter predicate against the
+ /// provided [`DataFile`]'s metrics. Used by [`TableScan`] to
+ /// see if this `DataFile` contains data that could match
+ /// the scan's filter.
+ #[allow(dead_code)]
+ pub(crate) fn eval(
+ filter: &'a BoundPredicate,
+ data_file: &'a DataFile,
+ schema: Schema,
+ ) -> crate::Result<bool> {
+ if data_file.record_count == 0 {
+ return ROWS_MUST_MATCH;
+ }
+
+ let mut evaluator = Self::new(data_file, schema);
+ visit(&mut evaluator, filter)
+ }
+
+ fn nan_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.nan_value_counts.get(&field_id)
+ }
+
+ fn null_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.null_value_counts.get(&field_id)
+ }
+
+ fn value_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.value_counts.get(&field_id)
+ }
+
+ fn lower_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.lower_bounds.get(&field_id)
+ }
+
+ fn upper_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.upper_bounds.get(&field_id)
+ }
+
+ fn contains_nans_only(&self, field_id: i32) -> bool {
+ let nan_count = self.nan_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ nan_count.is_some() && nan_count == value_count
+ }
+
+ fn contains_nulls_only(&self, field_id: i32) -> bool {
+ let null_count = self.null_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ null_count.is_some() && null_count == value_count
+ }
+
+ fn may_contain_null(&self, field_id: i32) -> bool {
+ if let Some(&null_count) = self.null_count(field_id) {
+ null_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn may_contain_nan(&self, field_id: i32) -> bool {
+ if let Some(&nan_count) = self.nan_count(field_id) {
+ nan_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn visit_inequality(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ cmp_fn: fn(&Datum, &Datum) -> bool,
+ use_lower_bound: bool,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if self.contains_nulls_only(field_id) || self.contains_nans_only(field_id) {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ if datum.is_nan() {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
Review Comment:
This diverges from Java, any reason to have the `NaN` explicit here?
I have never tried it, but I think you can compare it. It is mentioned in the spec for sorting:

##########
crates/iceberg/src/expr/visitors/strict_metrics_evaluator.rs:
##########
@@ -0,0 +1,1854 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use fnv::FnvHashSet;
+
+use crate::expr::visitors::bound_predicate_visitor::{visit, BoundPredicateVisitor};
+use crate::expr::{BoundPredicate, BoundReference};
+use crate::spec::{DataFile, Datum, Schema};
+use crate::Result;
+
+#[allow(dead_code)]
+const ROWS_MUST_MATCH: Result<bool> = Ok(true);
+#[allow(dead_code)]
+const ROWS_MIGHT_NOT_MATCH: Result<bool> = Ok(false);
+
+#[allow(dead_code)]
+pub(crate) struct StrictMetricsEvaluator<'a> {
+ data_file: &'a DataFile,
+ schema: Schema,
+}
+
+impl<'a> StrictMetricsEvaluator<'a> {
+ #[allow(dead_code)]
+ fn new(data_file: &'a DataFile, schema: Schema) -> Self {
+ StrictMetricsEvaluator { data_file, schema }
+ }
+
+ /// Evaluate this `StrictMetricsEvaluator`'s filter predicate against the
+ /// provided [`DataFile`]'s metrics. Used by [`TableScan`] to
+ /// see if this `DataFile` contains data that could match
+ /// the scan's filter.
+ #[allow(dead_code)]
+ pub(crate) fn eval(
+ filter: &'a BoundPredicate,
+ data_file: &'a DataFile,
+ schema: Schema,
+ ) -> crate::Result<bool> {
+ if data_file.record_count == 0 {
+ return ROWS_MUST_MATCH;
+ }
+
+ let mut evaluator = Self::new(data_file, schema);
+ visit(&mut evaluator, filter)
+ }
+
+ fn nan_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.nan_value_counts.get(&field_id)
+ }
+
+ fn null_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.null_value_counts.get(&field_id)
+ }
+
+ fn value_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.value_counts.get(&field_id)
+ }
+
+ fn lower_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.lower_bounds.get(&field_id)
+ }
+
+ fn upper_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.upper_bounds.get(&field_id)
+ }
+
+ fn contains_nans_only(&self, field_id: i32) -> bool {
+ let nan_count = self.nan_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ nan_count.is_some() && nan_count == value_count
+ }
+
+ fn contains_nulls_only(&self, field_id: i32) -> bool {
+ let null_count = self.null_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ null_count.is_some() && null_count == value_count
+ }
+
+ fn may_contain_null(&self, field_id: i32) -> bool {
+ if let Some(&null_count) = self.null_count(field_id) {
+ null_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn may_contain_nan(&self, field_id: i32) -> bool {
+ if let Some(&nan_count) = self.nan_count(field_id) {
+ nan_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn visit_inequality(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ cmp_fn: fn(&Datum, &Datum) -> bool,
+ use_lower_bound: bool,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if self.contains_nulls_only(field_id) || self.contains_nans_only(field_id) {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ if datum.is_nan() {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ let bound = if use_lower_bound {
+ self.lower_bound(field_id)
+ } else {
+ self.upper_bound(field_id)
+ };
+
+ if let Some(bound) = bound {
+ if cmp_fn(bound, datum) {
+ return ROWS_MUST_MATCH;
+ }
+
+ return ROWS_MIGHT_NOT_MATCH;
Review Comment:
Less is more :)
```suggestion
```
##########
crates/iceberg/src/expr/visitors/strict_metrics_evaluator.rs:
##########
@@ -0,0 +1,1854 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use fnv::FnvHashSet;
+
+use crate::expr::visitors::bound_predicate_visitor::{visit, BoundPredicateVisitor};
+use crate::expr::{BoundPredicate, BoundReference};
+use crate::spec::{DataFile, Datum, Schema};
+use crate::Result;
+
+#[allow(dead_code)]
+const ROWS_MUST_MATCH: Result<bool> = Ok(true);
+#[allow(dead_code)]
+const ROWS_MIGHT_NOT_MATCH: Result<bool> = Ok(false);
+
+#[allow(dead_code)]
+pub(crate) struct StrictMetricsEvaluator<'a> {
+ data_file: &'a DataFile,
+ schema: Schema,
+}
+
+impl<'a> StrictMetricsEvaluator<'a> {
+ #[allow(dead_code)]
+ fn new(data_file: &'a DataFile, schema: Schema) -> Self {
+ StrictMetricsEvaluator { data_file, schema }
+ }
+
+ /// Evaluate this `StrictMetricsEvaluator`'s filter predicate against the
+ /// provided [`DataFile`]'s metrics. Used by [`TableScan`] to
+ /// see if this `DataFile` contains data that could match
+ /// the scan's filter.
+ #[allow(dead_code)]
+ pub(crate) fn eval(
+ filter: &'a BoundPredicate,
+ data_file: &'a DataFile,
+ schema: Schema,
+ ) -> crate::Result<bool> {
+ if data_file.record_count == 0 {
+ return ROWS_MUST_MATCH;
+ }
+
+ let mut evaluator = Self::new(data_file, schema);
+ visit(&mut evaluator, filter)
+ }
+
+ fn nan_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.nan_value_counts.get(&field_id)
+ }
+
+ fn null_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.null_value_counts.get(&field_id)
+ }
+
+ fn value_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.value_counts.get(&field_id)
+ }
+
+ fn lower_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.lower_bounds.get(&field_id)
+ }
+
+ fn upper_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.upper_bounds.get(&field_id)
+ }
+
+ fn contains_nans_only(&self, field_id: i32) -> bool {
+ let nan_count = self.nan_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ nan_count.is_some() && nan_count == value_count
+ }
+
+ fn contains_nulls_only(&self, field_id: i32) -> bool {
+ let null_count = self.null_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ null_count.is_some() && null_count == value_count
+ }
+
+ fn may_contain_null(&self, field_id: i32) -> bool {
+ if let Some(&null_count) = self.null_count(field_id) {
+ null_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn may_contain_nan(&self, field_id: i32) -> bool {
+ if let Some(&nan_count) = self.nan_count(field_id) {
+ nan_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn visit_inequality(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ cmp_fn: fn(&Datum, &Datum) -> bool,
+ use_lower_bound: bool,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if self.contains_nulls_only(field_id) || self.contains_nans_only(field_id) {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ if datum.is_nan() {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ let bound = if use_lower_bound {
+ self.lower_bound(field_id)
+ } else {
+ self.upper_bound(field_id)
+ };
+
+ if let Some(bound) = bound {
+ if cmp_fn(bound, datum) {
+ return ROWS_MUST_MATCH;
+ }
+
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ ROWS_MIGHT_NOT_MATCH
+ }
+}
+
+impl BoundPredicateVisitor for StrictMetricsEvaluator<'_> {
+ type T = bool;
+
+ fn always_true(&mut self) -> crate::Result<bool> {
+ ROWS_MUST_MATCH
+ }
+
+ fn always_false(&mut self) -> crate::Result<bool> {
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn and(&mut self, lhs: bool, rhs: bool) -> crate::Result<bool> {
+ Ok(lhs && rhs)
+ }
+
+ fn or(&mut self, lhs: bool, rhs: bool) -> crate::Result<bool> {
+ Ok(lhs || rhs)
+ }
+
+ fn not(&mut self, inner: bool) -> crate::Result<bool> {
+ Ok(!inner)
+ }
+
+ fn is_null(
+ &mut self,
+ reference: &BoundReference,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if self.contains_nulls_only(field_id) {
+ return ROWS_MUST_MATCH;
+ }
+
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn not_null(
+ &mut self,
+ reference: &BoundReference,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if let Some(&count) = self.null_count(field_id) {
+ if count == 0 {
+ return ROWS_MUST_MATCH;
+ } else {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+ }
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn is_nan(
+ &mut self,
+ reference: &BoundReference,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ let contains_only = self.contains_nans_only(field_id);
+
+ if contains_only {
+ return ROWS_MUST_MATCH;
+ }
+
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn not_nan(
+ &mut self,
+ reference: &BoundReference,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if let Some(&nan_count) = self.nan_count(field_id) {
+ if nan_count == 0 {
+ return ROWS_MUST_MATCH;
+ }
+ }
+
+ if self.contains_nulls_only(field_id) {
+ return ROWS_MUST_MATCH;
+ }
+
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn less_than(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ self.visit_inequality(reference, datum, PartialOrd::lt, false)
+ }
+
+ fn less_than_or_eq(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ self.visit_inequality(reference, datum, PartialOrd::le, false)
+ }
+
+ fn greater_than(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ self.visit_inequality(reference, datum, PartialOrd::gt, true)
+ }
+
+ fn greater_than_or_eq(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ self.visit_inequality(reference, datum, PartialOrd::ge, true)
+ }
+
+ fn eq(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if self.may_contain_null(field_id) || self.may_contain_nan(field_id) {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ if let (Some(lower), Some(upper)) = (self.lower_bound(field_id), self.upper_bound(field_id))
+ {
+ // For an equality predicate to hold strictly, we must have:
+ // lower == literal.value == upper.
+ if lower.literal() != datum.literal() || upper.literal() != datum.literal() {
+ return ROWS_MIGHT_NOT_MATCH;
+ } else {
+ return ROWS_MUST_MATCH;
+ }
+ }
+
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn not_eq(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if self.may_contain_null(field_id) || self.may_contain_nan(field_id) {
+ return ROWS_MUST_MATCH;
+ }
+
+ if let Some(lower) = self.lower_bound(field_id) {
+ if lower.is_nan() {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+ if lower.literal() > datum.literal() {
+ return ROWS_MUST_MATCH;
+ }
+ }
+
+ if let Some(upper) = self.upper_bound(field_id) {
+ if upper.is_nan() {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+ if upper.literal() < datum.literal() {
+ return ROWS_MUST_MATCH;
+ }
+ }
+
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn starts_with(
+ &mut self,
+ _reference: &BoundReference,
+ _datum: &Datum,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn not_starts_with(
+ &mut self,
+ _reference: &BoundReference,
+ _datum: &Datum,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn r#in(
+ &mut self,
+ reference: &BoundReference,
+ literals: &FnvHashSet<Datum>,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if self.may_contain_null(field_id) || self.may_contain_nan(field_id) {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ if let (Some(lower), Some(upper)) = (self.lower_bound(field_id), self.upper_bound(field_id))
+ {
+ if !literals.contains(lower) || !literals.contains(upper) || lower != upper {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ return ROWS_MUST_MATCH;
+ }
+
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn not_in(
+ &mut self,
+ reference: &BoundReference,
+ literals: &FnvHashSet<Datum>,
+ _predicate: &BoundPredicate,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if self.may_contain_null(field_id) || self.may_contain_nan(field_id) {
+ return ROWS_MUST_MATCH;
+ }
Review Comment:
```suggestion
if self.contains_nulls_only(field_id) || self.contains_nans_only(field_id) {
return ROWS_MUST_MATCH;
}
```
https://github.com/apache/iceberg/blob/68189d28e973e0a14626869ddfb4cb572d5ef2ef/api/src/main/java/org/apache/iceberg/expressions/StrictMetricsEvaluator.java#L423-L425
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat: Add `StrictMetricsEvaluator` [iceberg-rust]
Posted by "liurenjie1024 (via GitHub)" <gi...@apache.org>.
liurenjie1024 merged PR #963:
URL: https://github.com/apache/iceberg-rust/pull/963
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat: Add `StrictMetricsEvaluator` [iceberg-rust]
Posted by "jonathanc-n (via GitHub)" <gi...@apache.org>.
jonathanc-n commented on code in PR #963:
URL: https://github.com/apache/iceberg-rust/pull/963#discussion_r1955029747
##########
crates/iceberg/src/expr/visitors/strict_metrics_evaluator.rs:
##########
@@ -0,0 +1,1854 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use fnv::FnvHashSet;
+
+use crate::expr::visitors::bound_predicate_visitor::{visit, BoundPredicateVisitor};
+use crate::expr::{BoundPredicate, BoundReference};
+use crate::spec::{DataFile, Datum, Schema};
+use crate::Result;
+
+#[allow(dead_code)]
+const ROWS_MUST_MATCH: Result<bool> = Ok(true);
+#[allow(dead_code)]
+const ROWS_MIGHT_NOT_MATCH: Result<bool> = Ok(false);
+
+#[allow(dead_code)]
+pub(crate) struct StrictMetricsEvaluator<'a> {
+ data_file: &'a DataFile,
+ schema: Schema,
+}
+
+impl<'a> StrictMetricsEvaluator<'a> {
+ #[allow(dead_code)]
+ fn new(data_file: &'a DataFile, schema: Schema) -> Self {
+ StrictMetricsEvaluator { data_file, schema }
+ }
+
+ /// Evaluate this `StrictMetricsEvaluator`'s filter predicate against the
+ /// provided [`DataFile`]'s metrics. Used by [`TableScan`] to
+ /// see if this `DataFile` contains data that could match
+ /// the scan's filter.
+ #[allow(dead_code)]
+ pub(crate) fn eval(
+ filter: &'a BoundPredicate,
+ data_file: &'a DataFile,
+ schema: Schema,
+ ) -> crate::Result<bool> {
+ if data_file.record_count == 0 {
+ return ROWS_MUST_MATCH;
+ }
+
+ let mut evaluator = Self::new(data_file, schema);
Review Comment:
The bound predicate visitor takes in a mutable reference of the evaluator. in rust you have to declare as mutable as well as pass it in with `mut` to let the compiler know the function can modify
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat: Add `StrictMetricsEvaluator` [iceberg-rust]
Posted by "jonathanc-n (via GitHub)" <gi...@apache.org>.
jonathanc-n commented on PR #963:
URL: https://github.com/apache/iceberg-rust/pull/963#issuecomment-2652648861
Tests will be added tomorrow.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat: Add `StrictMetricsEvaluator` [iceberg-rust]
Posted by "jonathanc-n (via GitHub)" <gi...@apache.org>.
jonathanc-n commented on code in PR #963:
URL: https://github.com/apache/iceberg-rust/pull/963#discussion_r1955029747
##########
crates/iceberg/src/expr/visitors/strict_metrics_evaluator.rs:
##########
@@ -0,0 +1,1854 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use fnv::FnvHashSet;
+
+use crate::expr::visitors::bound_predicate_visitor::{visit, BoundPredicateVisitor};
+use crate::expr::{BoundPredicate, BoundReference};
+use crate::spec::{DataFile, Datum, Schema};
+use crate::Result;
+
+#[allow(dead_code)]
+const ROWS_MUST_MATCH: Result<bool> = Ok(true);
+#[allow(dead_code)]
+const ROWS_MIGHT_NOT_MATCH: Result<bool> = Ok(false);
+
+#[allow(dead_code)]
+pub(crate) struct StrictMetricsEvaluator<'a> {
+ data_file: &'a DataFile,
+ schema: Schema,
+}
+
+impl<'a> StrictMetricsEvaluator<'a> {
+ #[allow(dead_code)]
+ fn new(data_file: &'a DataFile, schema: Schema) -> Self {
+ StrictMetricsEvaluator { data_file, schema }
+ }
+
+ /// Evaluate this `StrictMetricsEvaluator`'s filter predicate against the
+ /// provided [`DataFile`]'s metrics. Used by [`TableScan`] to
+ /// see if this `DataFile` contains data that could match
+ /// the scan's filter.
+ #[allow(dead_code)]
+ pub(crate) fn eval(
+ filter: &'a BoundPredicate,
+ data_file: &'a DataFile,
+ schema: Schema,
+ ) -> crate::Result<bool> {
+ if data_file.record_count == 0 {
+ return ROWS_MUST_MATCH;
+ }
+
+ let mut evaluator = Self::new(data_file, schema);
Review Comment:
This is mutable because the bound predicate visitor takes in a mutable reference of the evaluator. in rust you have to declare as mutable as well as pass it in with `mut` to let the compiler know the function can modify
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat: Add `StrictMetricsEvaluator` [iceberg-rust]
Posted by "jonathanc-n (via GitHub)" <gi...@apache.org>.
jonathanc-n commented on PR #963:
URL: https://github.com/apache/iceberg-rust/pull/963#issuecomment-2655357114
Tests have been added, this implementation follows the pyiceberg implementation. cc @Fokko @liurenjie1024 @ZENOTME
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat: Add `StrictMetricsEvaluator` [iceberg-rust]
Posted by "jonathanc-n (via GitHub)" <gi...@apache.org>.
jonathanc-n commented on PR #963:
URL: https://github.com/apache/iceberg-rust/pull/963#issuecomment-2657587163
@Fokko Thanks for the review. I got a bit mixed up with the logic with only nulls vs may contain null 😆. Should be good now
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat: Add `StrictMetricsEvaluator` [iceberg-rust]
Posted by "liurenjie1024 (via GitHub)" <gi...@apache.org>.
liurenjie1024 commented on code in PR #963:
URL: https://github.com/apache/iceberg-rust/pull/963#discussion_r1962804393
##########
crates/iceberg/src/expr/visitors/strict_metrics_evaluator.rs:
##########
@@ -0,0 +1,1567 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use fnv::FnvHashSet;
+
+use crate::expr::visitors::bound_predicate_visitor::{visit, BoundPredicateVisitor};
+use crate::expr::{BoundPredicate, BoundReference};
+use crate::spec::{DataFile, Datum};
+use crate::Result;
+
+#[allow(dead_code)]
+const ROWS_MUST_MATCH: Result<bool> = Ok(true);
+#[allow(dead_code)]
+const ROWS_MIGHT_NOT_MATCH: Result<bool> = Ok(false);
+
+#[allow(dead_code)]
+pub(crate) struct StrictMetricsEvaluator<'a> {
Review Comment:
It would be better to add comment to explain what this is for, we have good reference from java: https://github.com/apache/iceberg/blob/ca8a3a4d29799b7e0635b0feb1126b0d457618dd/api/src/main/java/org/apache/iceberg/expressions/StrictMetricsEvaluator.java#L37
##########
crates/iceberg/src/expr/visitors/strict_metrics_evaluator.rs:
##########
@@ -0,0 +1,1567 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use fnv::FnvHashSet;
+
+use crate::expr::visitors::bound_predicate_visitor::{visit, BoundPredicateVisitor};
+use crate::expr::{BoundPredicate, BoundReference};
+use crate::spec::{DataFile, Datum};
+use crate::Result;
+
+#[allow(dead_code)]
+const ROWS_MUST_MATCH: Result<bool> = Ok(true);
+#[allow(dead_code)]
+const ROWS_MIGHT_NOT_MATCH: Result<bool> = Ok(false);
+
+#[allow(dead_code)]
+pub(crate) struct StrictMetricsEvaluator<'a> {
+ data_file: &'a DataFile,
+}
+
+impl<'a> StrictMetricsEvaluator<'a> {
Review Comment:
Seems it has a lot of duplication with `InclusiveMetricsEvaluator`, maybe we could unify them in future.
##########
crates/iceberg/src/expr/visitors/strict_metrics_evaluator.rs:
##########
@@ -0,0 +1,1854 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use fnv::FnvHashSet;
+
+use crate::expr::visitors::bound_predicate_visitor::{visit, BoundPredicateVisitor};
+use crate::expr::{BoundPredicate, BoundReference};
+use crate::spec::{DataFile, Datum, Schema};
+use crate::Result;
+
+#[allow(dead_code)]
+const ROWS_MUST_MATCH: Result<bool> = Ok(true);
+#[allow(dead_code)]
+const ROWS_MIGHT_NOT_MATCH: Result<bool> = Ok(false);
+
+#[allow(dead_code)]
+pub(crate) struct StrictMetricsEvaluator<'a> {
+ data_file: &'a DataFile,
+ schema: Schema,
+}
+
+impl<'a> StrictMetricsEvaluator<'a> {
+ #[allow(dead_code)]
+ fn new(data_file: &'a DataFile, schema: Schema) -> Self {
+ StrictMetricsEvaluator { data_file, schema }
+ }
+
+ /// Evaluate this `StrictMetricsEvaluator`'s filter predicate against the
+ /// provided [`DataFile`]'s metrics. Used by [`TableScan`] to
+ /// see if this `DataFile` contains data that could match
+ /// the scan's filter.
+ #[allow(dead_code)]
+ pub(crate) fn eval(
+ filter: &'a BoundPredicate,
+ data_file: &'a DataFile,
+ schema: Schema,
+ ) -> crate::Result<bool> {
+ if data_file.record_count == 0 {
+ return ROWS_MUST_MATCH;
+ }
+
+ let mut evaluator = Self::new(data_file, schema);
+ visit(&mut evaluator, filter)
+ }
+
+ fn nan_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.nan_value_counts.get(&field_id)
+ }
+
+ fn null_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.null_value_counts.get(&field_id)
+ }
+
+ fn value_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.value_counts.get(&field_id)
+ }
+
+ fn lower_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.lower_bounds.get(&field_id)
+ }
+
+ fn upper_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.upper_bounds.get(&field_id)
+ }
+
+ fn contains_nans_only(&self, field_id: i32) -> bool {
+ let nan_count = self.nan_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ nan_count.is_some() && nan_count == value_count
+ }
+
+ fn contains_nulls_only(&self, field_id: i32) -> bool {
+ let null_count = self.null_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ null_count.is_some() && null_count == value_count
+ }
+
+ fn may_contain_null(&self, field_id: i32) -> bool {
+ if let Some(&null_count) = self.null_count(field_id) {
+ null_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn may_contain_nan(&self, field_id: i32) -> bool {
+ if let Some(&nan_count) = self.nan_count(field_id) {
+ nan_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn visit_inequality(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ cmp_fn: fn(&Datum, &Datum) -> bool,
+ use_lower_bound: bool,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if self.contains_nulls_only(field_id) || self.contains_nans_only(field_id) {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ if datum.is_nan() {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ let bound = if use_lower_bound {
+ self.lower_bound(field_id)
+ } else {
+ self.upper_bound(field_id)
+ };
+
+ if let Some(bound) = bound {
+ if cmp_fn(bound, datum) {
+ return ROWS_MUST_MATCH;
+ }
+
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ ROWS_MIGHT_NOT_MATCH
+ }
+}
+
+impl BoundPredicateVisitor for StrictMetricsEvaluator<'_> {
+ type T = bool;
+
+ fn always_true(&mut self) -> crate::Result<bool> {
+ ROWS_MUST_MATCH
+ }
+
+ fn always_false(&mut self) -> crate::Result<bool> {
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn and(&mut self, lhs: bool, rhs: bool) -> crate::Result<bool> {
+ Ok(lhs && rhs)
+ }
+
+ fn or(&mut self, lhs: bool, rhs: bool) -> crate::Result<bool> {
+ Ok(lhs || rhs)
+ }
+
+ fn not(&mut self, inner: bool) -> crate::Result<bool> {
+ Ok(!inner)
Review Comment:
Yes, they have been rewritten before evaluation: https://github.com/apache/iceberg-rust/blob/821f8dda3c4ebb635994e6acb8ed7914452f235f/crates/iceberg/src/expr/visitors/expression_evaluator.rs#L311
For inclusive metrics evaluator, we should consider creating an issue to track this.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat: Add `StrictMetricsEvaluator` [iceberg-rust]
Posted by "jonathanc-n (via GitHub)" <gi...@apache.org>.
jonathanc-n commented on PR #963:
URL: https://github.com/apache/iceberg-rust/pull/963#issuecomment-2673583467
@liurenjie1024 @Fokko Thank you for the reviews, problems should be resolved.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat: Add `StrictMetricsEvaluator` [iceberg-rust]
Posted by "jonathanc-n (via GitHub)" <gi...@apache.org>.
jonathanc-n commented on code in PR #963:
URL: https://github.com/apache/iceberg-rust/pull/963#discussion_r1955105071
##########
crates/iceberg/src/expr/visitors/strict_metrics_evaluator.rs:
##########
@@ -0,0 +1,1854 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use fnv::FnvHashSet;
+
+use crate::expr::visitors::bound_predicate_visitor::{visit, BoundPredicateVisitor};
+use crate::expr::{BoundPredicate, BoundReference};
+use crate::spec::{DataFile, Datum, Schema};
+use crate::Result;
+
+#[allow(dead_code)]
+const ROWS_MUST_MATCH: Result<bool> = Ok(true);
+#[allow(dead_code)]
+const ROWS_MIGHT_NOT_MATCH: Result<bool> = Ok(false);
+
+#[allow(dead_code)]
+pub(crate) struct StrictMetricsEvaluator<'a> {
+ data_file: &'a DataFile,
+ schema: Schema,
+}
+
+impl<'a> StrictMetricsEvaluator<'a> {
+ #[allow(dead_code)]
+ fn new(data_file: &'a DataFile, schema: Schema) -> Self {
+ StrictMetricsEvaluator { data_file, schema }
+ }
+
+ /// Evaluate this `StrictMetricsEvaluator`'s filter predicate against the
+ /// provided [`DataFile`]'s metrics. Used by [`TableScan`] to
+ /// see if this `DataFile` contains data that could match
+ /// the scan's filter.
+ #[allow(dead_code)]
+ pub(crate) fn eval(
+ filter: &'a BoundPredicate,
+ data_file: &'a DataFile,
+ schema: Schema,
+ ) -> crate::Result<bool> {
+ if data_file.record_count == 0 {
+ return ROWS_MUST_MATCH;
+ }
+
+ let mut evaluator = Self::new(data_file, schema);
+ visit(&mut evaluator, filter)
+ }
+
+ fn nan_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.nan_value_counts.get(&field_id)
+ }
+
+ fn null_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.null_value_counts.get(&field_id)
+ }
+
+ fn value_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.value_counts.get(&field_id)
+ }
+
+ fn lower_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.lower_bounds.get(&field_id)
+ }
+
+ fn upper_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.upper_bounds.get(&field_id)
+ }
+
+ fn contains_nans_only(&self, field_id: i32) -> bool {
+ let nan_count = self.nan_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ nan_count.is_some() && nan_count == value_count
+ }
+
+ fn contains_nulls_only(&self, field_id: i32) -> bool {
+ let null_count = self.null_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ null_count.is_some() && null_count == value_count
+ }
+
+ fn may_contain_null(&self, field_id: i32) -> bool {
+ if let Some(&null_count) = self.null_count(field_id) {
+ null_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn may_contain_nan(&self, field_id: i32) -> bool {
+ if let Some(&nan_count) = self.nan_count(field_id) {
+ nan_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn visit_inequality(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ cmp_fn: fn(&Datum, &Datum) -> bool,
+ use_lower_bound: bool,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if self.contains_nulls_only(field_id) || self.contains_nans_only(field_id) {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ if datum.is_nan() {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
Review Comment:
Yes good point, i moved the check into the greater_than function for only the lower bound
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat: Add `StrictMetricsEvaluator` [iceberg-rust]
Posted by "jonathanc-n (via GitHub)" <gi...@apache.org>.
jonathanc-n commented on code in PR #963:
URL: https://github.com/apache/iceberg-rust/pull/963#discussion_r1955094766
##########
crates/iceberg/src/expr/visitors/strict_metrics_evaluator.rs:
##########
@@ -0,0 +1,1854 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use fnv::FnvHashSet;
+
+use crate::expr::visitors::bound_predicate_visitor::{visit, BoundPredicateVisitor};
+use crate::expr::{BoundPredicate, BoundReference};
+use crate::spec::{DataFile, Datum, Schema};
+use crate::Result;
+
+#[allow(dead_code)]
+const ROWS_MUST_MATCH: Result<bool> = Ok(true);
+#[allow(dead_code)]
+const ROWS_MIGHT_NOT_MATCH: Result<bool> = Ok(false);
+
+#[allow(dead_code)]
+pub(crate) struct StrictMetricsEvaluator<'a> {
+ data_file: &'a DataFile,
+ schema: Schema,
+}
+
+impl<'a> StrictMetricsEvaluator<'a> {
+ #[allow(dead_code)]
+ fn new(data_file: &'a DataFile, schema: Schema) -> Self {
+ StrictMetricsEvaluator { data_file, schema }
+ }
+
+ /// Evaluate this `StrictMetricsEvaluator`'s filter predicate against the
+ /// provided [`DataFile`]'s metrics. Used by [`TableScan`] to
+ /// see if this `DataFile` contains data that could match
+ /// the scan's filter.
+ #[allow(dead_code)]
+ pub(crate) fn eval(
+ filter: &'a BoundPredicate,
+ data_file: &'a DataFile,
+ schema: Schema,
+ ) -> crate::Result<bool> {
+ if data_file.record_count == 0 {
+ return ROWS_MUST_MATCH;
+ }
+
+ let mut evaluator = Self::new(data_file, schema);
+ visit(&mut evaluator, filter)
+ }
+
+ fn nan_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.nan_value_counts.get(&field_id)
+ }
+
+ fn null_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.null_value_counts.get(&field_id)
+ }
+
+ fn value_count(&self, field_id: i32) -> Option<&u64> {
+ self.data_file.value_counts.get(&field_id)
+ }
+
+ fn lower_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.lower_bounds.get(&field_id)
+ }
+
+ fn upper_bound(&self, field_id: i32) -> Option<&Datum> {
+ self.data_file.upper_bounds.get(&field_id)
+ }
+
+ fn contains_nans_only(&self, field_id: i32) -> bool {
+ let nan_count = self.nan_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ nan_count.is_some() && nan_count == value_count
+ }
+
+ fn contains_nulls_only(&self, field_id: i32) -> bool {
+ let null_count = self.null_count(field_id);
+ let value_count = self.value_count(field_id);
+
+ null_count.is_some() && null_count == value_count
+ }
+
+ fn may_contain_null(&self, field_id: i32) -> bool {
+ if let Some(&null_count) = self.null_count(field_id) {
+ null_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn may_contain_nan(&self, field_id: i32) -> bool {
+ if let Some(&nan_count) = self.nan_count(field_id) {
+ nan_count > 0
+ } else {
+ true
+ }
+ }
+
+ fn visit_inequality(
+ &mut self,
+ reference: &BoundReference,
+ datum: &Datum,
+ cmp_fn: fn(&Datum, &Datum) -> bool,
+ use_lower_bound: bool,
+ ) -> crate::Result<bool> {
+ let field_id = reference.field().id;
+
+ if self.contains_nulls_only(field_id) || self.contains_nans_only(field_id) {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ if datum.is_nan() {
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ let bound = if use_lower_bound {
+ self.lower_bound(field_id)
+ } else {
+ self.upper_bound(field_id)
+ };
+
+ if let Some(bound) = bound {
+ if cmp_fn(bound, datum) {
+ return ROWS_MUST_MATCH;
+ }
+
+ return ROWS_MIGHT_NOT_MATCH;
+ }
+
+ ROWS_MIGHT_NOT_MATCH
+ }
+}
+
+impl BoundPredicateVisitor for StrictMetricsEvaluator<'_> {
+ type T = bool;
+
+ fn always_true(&mut self) -> crate::Result<bool> {
+ ROWS_MUST_MATCH
+ }
+
+ fn always_false(&mut self) -> crate::Result<bool> {
+ ROWS_MIGHT_NOT_MATCH
+ }
+
+ fn and(&mut self, lhs: bool, rhs: bool) -> crate::Result<bool> {
+ Ok(lhs && rhs)
+ }
+
+ fn or(&mut self, lhs: bool, rhs: bool) -> crate::Result<bool> {
+ Ok(lhs || rhs)
+ }
+
+ fn not(&mut self, inner: bool) -> crate::Result<bool> {
+ Ok(!inner)
Review Comment:
Is there a rewrite performed? The inclusive metric evaluator in rust also returns it as such.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org