Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyiceberg/partitioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ def __init__(
@classmethod
def map_source_ids_onto_source_id(cls, data: Any) -> Any:
if isinstance(data, dict):
if "source-id" not in data and (source_ids := data["source-ids"]):
if "source-id" not in data and "source-ids" in data:
source_ids = data["source-ids"]
if isinstance(source_ids, list):
if len(source_ids) == 0:
raise ValueError("Empty source-ids is not allowed")
Expand Down
3 changes: 2 additions & 1 deletion pyiceberg/table/sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def set_null_order(cls, values: dict[str, Any]) -> dict[str, Any]:
@classmethod
def map_source_ids_onto_source_id(cls, data: Any) -> Any:
if isinstance(data, dict):
if "source-id" not in data and (source_ids := data["source-ids"]):
if "source-id" not in data and "source-ids" in data:
source_ids = data["source-ids"]
if isinstance(source_ids, list):
if len(source_ids) == 0:
raise ValueError("Empty source-ids is not allowed")
Expand Down
6 changes: 6 additions & 0 deletions tests/table/test_partitioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ def test_deserialize_partition_field_v3() -> None:
assert field == PartitionField(source_id=1, field_id=1000, transform=TruncateTransform(width=19), name="str_truncate")


def test_deserialize_partition_field_empty_source_ids_rejected() -> None:
json_partition_spec = """{"source-ids": [], "field-id": 1000, "transform": "identity", "name": "x"}"""
with pytest.raises(Exception, match="Empty source-ids is not allowed"):
PartitionField.model_validate_json(json_partition_spec)


def test_incompatible_source_column_not_found() -> None:
schema = Schema(NestedField(1, "foo", IntegerType()), NestedField(2, "bar", IntegerType()))

Expand Down
6 changes: 6 additions & 0 deletions tests/table/test_sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ def test_serialize_sort_field_v3() -> None:
assert SortField.model_validate_json(payload) == expected


def test_deserialize_sort_field_empty_source_ids_rejected() -> None:
payload = '{"source-ids":[],"transform":"identity","direction":"asc","null-order":"nulls-first"}'
with pytest.raises(Exception, match="Empty source-ids is not allowed"):
SortField.model_validate_json(payload)


def test_incompatible_source_column_not_found(sort_order: SortOrder) -> None:
schema = Schema(NestedField(1, "foo", IntegerType()), NestedField(2, "bar", IntegerType()))

Expand Down