This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git
The following commit(s) were added to refs/heads/main by this push:
new f323f2895 Encode * and ~ in partition paths the way Java does (#4443)
f323f2895 is described below
commit f323f289581bfb3f29fd3b4b806f4748045cae5f
Author: Gedalia Kliger <[email protected]>
AuthorDate: Sat Nov 21 06:54:36 2026 +0000
Encode * and ~ in partition paths the way Java does (#4443)
partition_to_path uses quote_plus to match java.net.URLEncoder, but the
two differ on "*" (Java keeps it) and "~" (Java escapes it), so the
same partition got a different path from PyIceberg than from Java.
---
pyiceberg/partitioning.py | 9 +++++++--
tests/table/test_partitioning.py | 8 ++++++++
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/pyiceberg/partitioning.py b/pyiceberg/partitioning.py
index 6d79dce18..f557d4a7e 100644
--- a/pyiceberg/partitioning.py
+++ b/pyiceberg/partitioning.py
@@ -68,6 +68,11 @@ INITIAL_PARTITION_SPEC_ID = 0
PARTITION_FIELD_ID_START: int = 1000
+def _url_encode(value: str) -> str:
+ # Unlike quote_plus, java.net.URLEncoder leaves "*" as is and escapes "~"
+ return quote_plus(value, safe="*").replace("~", "%7E")
+
+
class PartitionField(IcebergBaseModel):
"""PartitionField represents how one partition value is derived from the
source column via transformation.
@@ -248,8 +253,8 @@ class PartitionSpec(IcebergBaseModel):
partition_field = self.fields[pos]
value_str =
partition_field.transform.to_human_string(field_types[pos].field_type,
value=data[pos])
- value_strs.append(quote_plus(value_str, safe=""))
- field_strs.append(quote_plus(partition_field.name, safe=""))
+ value_strs.append(_url_encode(value_str))
+ field_strs.append(_url_encode(partition_field.name))
path = "/".join([field_str + "=" + value_str for field_str, value_str
in zip(field_strs, value_strs, strict=True)])
return path
diff --git a/tests/table/test_partitioning.py b/tests/table/test_partitioning.py
index 17b465e7e..1f24cfccd 100644
--- a/tests/table/test_partitioning.py
+++ b/tests/table/test_partitioning.py
@@ -172,6 +172,14 @@ def test_partition_spec_to_path() -> None:
assert spec.partition_to_path(record, schema) ==
"my%23str%25bucket=my%2Bstr/other+str%2Bbucket=%28+%29/my%21int%3Abucket=10"
+def test_partition_spec_to_path_asterisk_and_tilde() -> None:
+ schema = Schema(NestedField(field_id=1, name="str",
field_type=StringType(), required=False))
+ spec = PartitionSpec(PartitionField(source_id=1, field_id=1000,
transform=IdentityTransform(), name="my*str~field"))
+
+ # java.net.URLEncoder leaves "*" as is and escapes "~"
+ assert spec.partition_to_path(Record("a*b~c-d_e.f"), schema) ==
"my*str%7Efield=a*b%7Ec-d_e.f"
+
+
def test_partition_spec_to_path_dropped_source_id() -> None:
schema = Schema(
NestedField(field_id=1, name="str", field_type=StringType(),
required=False),