You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "geruh (via GitHub)" <gi...@apache.org> on 2025/11/30 22:56:35 UTC
Re: [PR] Read partitioned tables with source field missing from schema [iceberg-python]
geruh commented on code in PR #2367:
URL: https://github.com/apache/iceberg-python/pull/2367#discussion_r2575096299
##########
tests/table/test_partitioning.py:
##########
@@ -178,6 +179,19 @@ def test_partition_type(table_schema_simple: Schema) -> None:
)
+def test_partition_type_missing_source_field(table_schema_simple: Schema) -> None:
+ spec = PartitionSpec(
+ PartitionField(source_id=1, field_id=1000, transform=TruncateTransform(width=19), name="str_truncate"),
+ PartitionField(source_id=10, field_id=1001, transform=BucketTransform(num_buckets=25), name="int_bucket"),
+ spec_id=3,
+ )
+
+ assert spec.partition_type(table_schema_simple) == StructType(
+ NestedField(field_id=1000, name="str_truncate", field_type=StringType(), required=False),
+ NestedField(field_id=1001, name="int_bucket", field_type=UnknownType(), required=False),
+ )
+
+
Review Comment:
Can we also add a test or two to ensure that the behavior of `partition_to_path` is correct
##########
pyiceberg/partitioning.py:
##########
@@ -222,11 +223,13 @@ def partition_type(self, schema: Schema) -> StructType:
:return: A StructType that represents the PartitionSpec, with a NestedField for each PartitionField.
"""
nested_fields = []
+ schema_ids = index_by_id(schema)
for field in self.fields:
- source_type = schema.find_type(field.source_id)
- result_type = field.transform.result_type(source_type)
- required = schema.find_field(field.source_id).required
- nested_fields.append(NestedField(field.field_id, field.name, result_type, required=required))
+ if source_field := schema_ids.get(field.source_id):
+ result_type = field.transform.result_type(source_field.field_type)
+ nested_fields.append(NestedField(field.field_id, field.name, result_type, required=source_field.required))
+ else:
Review Comment:
Nit: can we add a comment here to explain why the `UnknownType` is used
--
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