rdblue commented on code in PR #5931:
URL: https://github.com/apache/iceberg/pull/5931#discussion_r989558008
##########
python/pyiceberg/schema.py:
##########
@@ -795,3 +796,150 @@ def map(self, map_type: MapType, key_result: Callable[[],
IcebergType], value_re
def primitive(self, primitive: PrimitiveType) -> PrimitiveType:
return primitive
+
+
+def prune_columns(schema: Schema, selected: Set[int], select_full_types: bool)
-> Schema:
+ result = visit(schema.as_struct(), _PruneColumnsVisitor(selected,
select_full_types))
+
+ if not isinstance(result, StructType):
+ raise ValueError(f"Expected StructType, got: {result}")
+
+ return Schema(*result.fields, schema_id=schema.schema_id,
identifier_field_ids=schema.identifier_field_ids)
+
+
+class _PruneColumnsVisitor(SchemaVisitor[Optional[IcebergType]]):
Review Comment:
This implementation looks correct to me.
--
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]