ZENOTME commented on code in PR #731:
URL: https://github.com/apache/iceberg-rust/pull/731#discussion_r1899341695


##########
crates/iceberg/src/spec/schema.rs:
##########
@@ -1132,6 +1132,213 @@ impl ReassignFieldIds {
     }
 }
 
+/// A post order schema visitor with partner.
+///
+/// For order of methods called, please refer to [`visit_schema_with_partner`].
+pub trait SchemaWithPartnerVisitor<P> {
+    /// Return type of this visitor.
+    type T;
+
+    /// Called before struct field.
+    fn before_struct_field(&mut self, _field: &NestedFieldRef, _partner: &P) 
-> Result<()> {
+        Ok(())
+    }
+    /// Called after struct field.
+    fn after_struct_field(&mut self, _field: &NestedFieldRef, _partner: &P) -> 
Result<()> {
+        Ok(())
+    }
+    /// Called before list field.
+    fn before_list_element(&mut self, _field: &NestedFieldRef, _partner: &P) 
-> Result<()> {
+        Ok(())
+    }
+    /// Called after list field.
+    fn after_list_element(&mut self, _field: &NestedFieldRef, _partner: &P) -> 
Result<()> {
+        Ok(())
+    }
+    /// Called before map key field.
+    fn before_map_key(&mut self, _field: &NestedFieldRef, _partner: &P) -> 
Result<()> {
+        Ok(())
+    }
+    /// Called after map key field.
+    fn after_map_key(&mut self, _field: &NestedFieldRef, _partner: &P) -> 
Result<()> {
+        Ok(())
+    }
+    /// Called before map value field.
+    fn before_map_value(&mut self, _field: &NestedFieldRef, _partner: &P) -> 
Result<()> {
+        Ok(())
+    }
+    /// Called after map value field.
+    fn after_map_value(&mut self, _field: &NestedFieldRef, _partner: &P) -> 
Result<()> {
+        Ok(())
+    }
+
+    /// Called before every type, if this function return `Some`, the 
following visiting will be skipped.
+    /// This function used to implement early return.
+    fn visit_type_before(&mut self, _ty: &Type, _partner: &P) -> 
Result<Option<Self::T>> {

Review Comment:
   > why we don't prune unnecessary fields before visiting?
   
   I think this prune will also incur visits recursively. Let me explain why we 
need this prune. In arrow, the struct array maybe represent as a nullarray 
which means that all child field are null. So in this case, we need to 
recognize this and stop to visit child column. But in our visitor pattern, we 
can't control this, the control path is in the visit_function rather than 
vistor. So we need to use this function to notify the visit function that stop 
visit child column if this function return Some. 
   



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