smaheshwar-pltr commented on code in PR #1457:
URL: https://github.com/apache/iceberg-python/pull/1457#discussion_r1895780803


##########
tests/table/test_partitioning.py:
##########
@@ -118,6 +119,27 @@ def test_deserialize_partition_spec() -> None:
     )
 
 
+def test_partition_spec_to_path() -> None:
+    schema = Schema(
+        NestedField(field_id=1, name="str", field_type=StringType(), 
required=False),
+        NestedField(field_id=2, name="other_str", field_type=StringType(), 
required=False),
+        NestedField(field_id=3, name="int", field_type=IntegerType(), 
required=True),
+    )
+
+    spec = PartitionSpec(
+        PartitionField(source_id=1, field_id=1000, 
transform=TruncateTransform(width=19), name="my#str%bucket"),
+        PartitionField(source_id=2, field_id=1001, 
transform=IdentityTransform(), name="other str+bucket"),
+        PartitionField(source_id=3, field_id=1002, 
transform=BucketTransform(num_buckets=25), name="my!int:bucket"),
+        spec_id=3,
+    )
+
+    record = Record(**{"my#str%bucket": "my+str", "other str+bucket": "( )", 
"my!int:bucket": 10})  # type: ignore
+
+    # Both partition names fields and values should be URL encoded, with 
spaces mapping to plus signs, to match the Java
+    # behaviour: 
https://github.com/apache/iceberg/blob/ca3db931b0f024f0412084751ac85dd4ef2da7e7/api/src/main/java/org/apache/iceberg/PartitionSpec.java#L198-L204
+    assert spec.partition_to_path(record, schema) == 
"my%23str%25bucket=my%2Bstr/other+str%2Bbucket=%28+%29/my%21int%3Abucket=10"

Review Comment:
   Cross-checked with Java implementation (integration tests will do this 
eventually), in particular WRT to ' ' and '+' encoding. It is consistent.



-- 
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