Skip to content

Commit d4928bd

Browse files
committed
small refactor
1 parent 348f4c7 commit d4928bd

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

pyiceberg/partitioning.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -267,20 +267,17 @@ def validate_parents_are_structs(field_id: int) -> None:
267267
continue
268268

269269
if not isinstance(field.transform, VoidTransform):
270-
if not is_source_column_in_schema:
270+
if source_field := schema_fields.get(field.source_id):
271+
source_type = source_field.field_type
272+
if not source_type.is_primitive:
273+
raise ValidationError(f"Cannot partition by non-primitive source field: {source_type}")
274+
if not field.transform.can_transform(source_type):
275+
raise ValidationError(f"Invalid source type {source_type} for transform: {field.transform}")
276+
# The only valid parent types for a PartitionField are StructTypes. This must be checked recursively
277+
validate_parents_are_structs(field.source_id)
278+
else:
271279
raise ValidationError(f"Cannot find source column for partition field: {field}")
272280

273-
source_type = schema.find_type(field.source_id)
274-
275-
if not source_type.is_primitive:
276-
raise ValidationError(f"Cannot partition by non-primitive source field: {source_type}")
277-
278-
if not field.transform.can_transform(source_type):
279-
raise ValidationError(f"Invalid source type {source_type} for transform: {field.transform}")
280-
281-
# The only valid parent types for a PartitionField are StructTypes. This must be checked recursively
282-
validate_parents_are_structs(field.source_id)
283-
284281

285282
UNPARTITIONED_PARTITION_SPEC = PartitionSpec(spec_id=0)
286283

0 commit comments

Comments
 (0)