This is an automated email from the ASF dual-hosted git repository.
fokko 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 150fa0cf Set default for `SortField`'s `transform` (#1347)
150fa0cf is described below
commit 150fa0cfa38427012b4afd237813cf2603c5a5c3
Author: Kevin Liu <[email protected]>
AuthorDate: Wed Nov 20 02:42:16 2024 -0500
Set default for `SortField`'s `transform` (#1347)
* add default
* add test
---
pyiceberg/table/sorting.py | 2 +-
tests/table/test_sorting.py | 7 +++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/pyiceberg/table/sorting.py b/pyiceberg/table/sorting.py
index f74d5bc7..64d56f0e 100644
--- a/pyiceberg/table/sorting.py
+++ b/pyiceberg/table/sorting.py
@@ -108,7 +108,7 @@ class SortField(IcebergBaseModel):
BeforeValidator(parse_transform),
PlainSerializer(lambda c: str(c), return_type=str), # pylint:
disable=W0108
WithJsonSchema({"type": "string"}, mode="serialization"),
- ] = Field()
+ ] = Field(default=IdentityTransform())
direction: SortDirection = Field()
null_order: NullOrder = Field(alias="null-order")
diff --git a/tests/table/test_sorting.py b/tests/table/test_sorting.py
index 6b411936..977ff9d5 100644
--- a/tests/table/test_sorting.py
+++ b/tests/table/test_sorting.py
@@ -41,6 +41,13 @@ def sort_order() -> SortOrder:
)
+def test_serialize_sort_order_default() -> None:
+ assert (
+ SortOrder(SortField(source_id=19)).model_dump_json()
+ ==
'{"order-id":1,"fields":[{"source-id":19,"transform":"identity","direction":"asc","null-order":"nulls-first"}]}'
+ )
+
+
def test_serialize_sort_order_unsorted() -> None:
assert UNSORTED_SORT_ORDER.model_dump_json() ==
'{"order-id":0,"fields":[]}'