rdblue commented on code in PR #6997:
URL: https://github.com/apache/iceberg/pull/6997#discussion_r1168050701


##########
python/pyiceberg/io/pyarrow.py:
##########
@@ -486,6 +499,207 @@ def expression_to_pyarrow(expr: BooleanExpression) -> 
pc.Expression:
     return boolean_expression_visit(expr, _ConvertToArrowExpression())
 
 
+def pyarrow_to_schema(schema: pa.Schema) -> Schema:
+    visitor = _ConvertToIceberg()
+    struct_results: List[Optional[IcebergType]] = []
+    for field in schema:
+        visitor.before_field(field)
+        struct_result = visit_pyarrow(field.type, visitor)
+        visitor.after_field(field)
+        struct_results.append(struct_result)
+    return visitor.schema(schema, struct_results)

Review Comment:
   Why isn't this done in the `visit_pyarrow` method? It seems incorrect to 
have top-level logic that must be copied into every function that uses a 
visitor.
   
   I'd expect something like this:
   
   ```python
   @visit_pyarrow.register(pa.Schema)
   def _(schema: pa.Schema, visitor: PyArrowSchemaVisitor[T]) -> T
       field_results: List[Optional[T]] = []
       for field in schema:
           ...
       return visitor.schema(schema, field_results)
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to