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


##########
crates/iceberg/src/expr/visitors/bound_predicate_evaluator.rs:
##########
@@ -0,0 +1,339 @@
+// 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 crate::expr::{BoundPredicate, BoundReference, PredicateOperator};
+use crate::spec::Datum;
+use crate::Result;
+use fnv::FnvHashSet;
+
+pub trait BoundPredicateEvaluator {
+    fn visit(&mut self, node: &BoundPredicate) -> Result<bool> {
+        match node {

Review Comment:
   according to the design suggestion by @liurenjie1024 
[link](https://github.com/apache/iceberg-rust/pull/241#issuecomment-2033371130) 
this function should live outside the trait as `fn visit_bound_predicate`. 
Other than that traversal logic looks fine.



##########
crates/iceberg/src/expr/visitors/bound_predicate_evaluator.rs:
##########
@@ -0,0 +1,339 @@
+// 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 crate::expr::{BoundPredicate, BoundReference, PredicateOperator};
+use crate::spec::Datum;
+use crate::Result;
+use fnv::FnvHashSet;
+
+pub trait BoundPredicateEvaluator {

Review Comment:
   nit: Perhaps we can move the complete trait into /visitors/mod.rs? However, 
I am not sure about this - so I'd appreciate your thoughts on this.



##########
crates/iceberg/src/expr/visitors/manifest_evaluator.rs:
##########
@@ -0,0 +1,181 @@
+// 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 crate::expr::visitors::bound_predicate_evaluator::BoundPredicateEvaluator;
+use crate::expr::visitors::inclusive_projection::InclusiveProjection;
+use crate::expr::{Bind, BoundPredicate, BoundReference};
+use crate::spec::{Datum, FieldSummary, ManifestFile, PartitionSpecRef, Schema, 
SchemaRef};
+use fnv::FnvHashSet;
+use std::sync::Arc;
+
+pub(crate) struct ManifestEvaluatorFactory {
+    partition_schema: SchemaRef,
+    partition_filter: BoundPredicate,
+    case_sensitive: bool,
+}
+
+impl ManifestEvaluatorFactory {

Review Comment:
   Perhaps we can turn this into a proper `Builder` similar to the [python 
function](https://github.com/apache/iceberg-python/blob/main/pyiceberg/table/__init__.py#L1485).
 I'm thinking `ManifestEvaluatorBuilder` as a derived `TypedBuilder` would 
probably be enough. This way we can provide `table_schema`, `partition_spec` 
and the `row_filter` and orchestrate the `InclusiveProjection` when we call 
`eval` on the `ManifestEvaluator` itself? What do you think?



##########
crates/iceberg/src/expr/visitors/bound_predicate_evaluator.rs:
##########
@@ -0,0 +1,339 @@
+// 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 crate::expr::{BoundPredicate, BoundReference, PredicateOperator};
+use crate::spec::Datum;
+use crate::Result;
+use fnv::FnvHashSet;
+
+pub trait BoundPredicateEvaluator {

Review Comment:
   I think, it'd be better to rename this to `BoundPredicateVisitor`



##########
crates/iceberg/src/expr/visitors/inclusive_projection.rs:
##########
@@ -0,0 +1,86 @@
+// 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 crate::expr::{BoundPredicate, Predicate};
+use crate::spec::{PartitionField, PartitionSpecRef, SchemaRef};
+
+pub(crate) struct InclusiveProjection {
+    #[allow(dead_code)]
+    table_schema: SchemaRef,
+    partition_spec: PartitionSpecRef,
+}
+
+impl InclusiveProjection {

Review Comment:
   I'll guess this will be done in the new PR - `InclusiveProjection` should 
impl `pub trait BoundPredicateVisitor`



##########
crates/iceberg/src/expr/visitors/manifest_evaluator.rs:
##########
@@ -0,0 +1,181 @@
+// 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 crate::expr::visitors::bound_predicate_evaluator::BoundPredicateEvaluator;
+use crate::expr::visitors::inclusive_projection::InclusiveProjection;
+use crate::expr::{Bind, BoundPredicate, BoundReference};
+use crate::spec::{Datum, FieldSummary, ManifestFile, PartitionSpecRef, Schema, 
SchemaRef};
+use fnv::FnvHashSet;
+use std::sync::Arc;
+
+pub(crate) struct ManifestEvaluatorFactory {
+    partition_schema: SchemaRef,
+    partition_filter: BoundPredicate,
+    case_sensitive: bool,
+}
+
+impl ManifestEvaluatorFactory {
+    pub(crate) fn new(
+        partition_spec: PartitionSpecRef,
+        table_schema: SchemaRef,
+        partition_filter: BoundPredicate,
+        case_sensitive: bool,
+    ) -> crate::Result<Self> {
+        let partition_type = partition_spec.partition_type(&table_schema)?;
+
+        // this is needed as SchemaBuilder.with_fields expects an iterator over
+        // Arc<NestedField> rather than &Arc<NestedField>
+        let cloned_partition_fields: Vec<_> =
+            partition_type.fields().iter().map(Arc::clone).collect();
+
+        let partition_schema = Schema::builder()
+            .with_fields(cloned_partition_fields)
+            .build()?;
+
+        let partition_schema_ref = Arc::new(partition_schema);
+
+        let inclusive_projection =
+            InclusiveProjection::new(table_schema.clone(), 
partition_spec.clone());
+        let unbound_partition_filter = 
inclusive_projection.project(&partition_filter)?;
+
+        let partition_filter =
+            unbound_partition_filter.bind(partition_schema_ref.clone(), 
case_sensitive)?;
+
+        Ok(Self {
+            partition_schema: partition_schema_ref,
+            partition_filter,
+            case_sensitive,
+        })
+    }
+
+    pub(crate) fn evaluate(&self, manifest_file: &ManifestFile) -> 
crate::Result<bool> {

Review Comment:
   nit: rename to `eval`



##########
crates/iceberg/src/expr/visitors/inclusive_projection.rs:
##########
@@ -0,0 +1,86 @@
+// 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 crate::expr::{BoundPredicate, Predicate};
+use crate::spec::{PartitionField, PartitionSpecRef, SchemaRef};
+
+pub(crate) struct InclusiveProjection {
+    #[allow(dead_code)]
+    table_schema: SchemaRef,
+    partition_spec: PartitionSpecRef,
+}
+
+impl InclusiveProjection {
+    pub(crate) fn new(table_schema: SchemaRef, partition_spec: 
PartitionSpecRef) -> Self {
+        Self {
+            table_schema,
+            partition_spec,
+        }
+    }
+
+    pub(crate) fn project(&self, predicate: &BoundPredicate) -> 
crate::Result<Predicate> {

Review Comment:
   nit: although it does align with the Python impl. I'd rename this to `eval` 
to keep it consistent across all `visitors`



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