2626 Optional ,
2727 Tuple ,
2828)
29+ from urllib .parse import quote
2930
3031from pydantic import (
3132 BeforeValidator ,
@@ -208,7 +209,6 @@ def partition_to_path(self, data: Record, schema: Schema) -> str:
208209
209210 partition_field = self .fields [pos ] # partition field
210211 value_str = partition_field .transform .to_human_string (field_types [pos ].field_type , value = value )
211- from urllib .parse import quote
212212
213213 value_str = quote (value_str , safe = '' )
214214 value_strs .append (value_str )
@@ -250,10 +250,9 @@ class PartitionFieldValue:
250250
251251@dataclass (frozen = True )
252252class PartitionKey :
253- raw_partition_field_values : list [PartitionFieldValue ]
253+ raw_partition_field_values : List [PartitionFieldValue ]
254254 partition_spec : PartitionSpec
255255 schema : Schema
256- from functools import cached_property
257256
258257 @cached_property
259258 def partition (self ) -> Record : # partition key in iceberg type
@@ -263,8 +262,8 @@ def partition(self) -> Record: # partition key in iceberg type
263262 assert len (partition_fields ) == 1
264263 partition_field = partition_fields [0 ]
265264 iceberg_type = self .schema .find_field (name_or_id = raw_partition_field_value .field .source_id ).field_type
266- _iceberg_typed_value = iceberg_typed_value (iceberg_type , raw_partition_field_value .value )
267- transformed_value = partition_field .transform .transform (iceberg_type )(_iceberg_typed_value )
265+ iceberg_typed_value = _to_iceberg_type (iceberg_type , raw_partition_field_value .value )
266+ transformed_value = partition_field .transform .transform (iceberg_type )(iceberg_typed_value )
268267 iceberg_typed_key_values [partition_field .name ] = transformed_value
269268 return Record (** iceberg_typed_key_values )
270269
@@ -273,21 +272,21 @@ def to_path(self) -> str:
273272
274273
275274@singledispatch
276- def iceberg_typed_value (type : IcebergType , value : Any ) -> Any :
275+ def _to_iceberg_type (type : IcebergType , value : Any ) -> Any :
277276 return TypeError (f"Unsupported partition field type: { type } " )
278277
279278
280- @iceberg_typed_value .register (TimestampType )
281- @iceberg_typed_value .register (TimestamptzType )
279+ @_to_iceberg_type .register (TimestampType )
280+ @_to_iceberg_type .register (TimestamptzType )
282281def _ (type : IcebergType , value : Optional [datetime ]) -> Optional [int ]:
283282 return datetime_to_micros (value ) if value is not None else None
284283
285284
286- @iceberg_typed_value .register (DateType )
285+ @_to_iceberg_type .register (DateType )
287286def _ (type : IcebergType , value : Optional [date ]) -> Optional [int ]:
288287 return date_to_days (value ) if value is not None else None
289288
290289
291- @iceberg_typed_value .register (PrimitiveType )
290+ @_to_iceberg_type .register (PrimitiveType )
292291def _ (type : IcebergType , value : Optional [Any ]) -> Optional [Any ]:
293292 return value
0 commit comments