Skip to content

Commit 9610b41

Browse files
authored
fix: Set Expression serialization to use 'values' (#2782)
Related to #2775 # Rationale for this change Update the Set Expression serialization to align with the REST spec. Today, the set expression literals are serialized under items, instead of values. For instance: ```json { "term": "foo", "type": "not-in", "items": [ 1, 2, 3 ] } ``` When it should be: ```json { "term": "foo", "type": "not-in", "values": [ 1, 2, 3 ] } ``` **Rest ref**: https://github.com/apache/iceberg/blob/47d5f5009eafbbb526e6e2c9cbeac3105bf34670/open-api/rest-catalog-open-api.yaml#L2353 **Expression ref**: https://github.com/apache/iceberg/blob/d19e3ff07653167d902865281601a5da4e2f2def/core/src/main/java/org/apache/iceberg/expressions/ExpressionParser.java#L189-L192 ## Are these changes tested? Yes ## Are there any user-facing changes? only serialization, and initialization stays the same.
1 parent 6806207 commit 9610b41

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

pyiceberg/expressions/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,11 +596,11 @@ class SetPredicate(IcebergBaseModel, UnboundPredicate, ABC):
596596
model_config = ConfigDict(arbitrary_types_allowed=True)
597597

598598
type: TypingLiteral["in", "not-in"] = Field(default="in")
599-
literals: set[LiteralValue] = Field(alias="items")
599+
literals: set[LiteralValue] = Field(alias="values")
600600

601601
def __init__(self, term: str | UnboundTerm, literals: Iterable[Any] | Iterable[LiteralValue]):
602602
literal_set = _to_literal_set(literals)
603-
super().__init__(term=_to_unbound_term(term), items=literal_set) # type: ignore
603+
super().__init__(term=_to_unbound_term(term), values=literal_set) # type: ignore
604604
object.__setattr__(self, "literals", literal_set)
605605

606606
def bind(self, schema: Schema, case_sensitive: bool = True) -> BoundSetPredicate:

tests/expressions/test_expressions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -915,12 +915,12 @@ def test_not_in() -> None:
915915

916916
def test_serialize_in() -> None:
917917
pred = In(term="foo", literals=[1, 2, 3])
918-
assert pred.model_dump_json() == '{"term":"foo","type":"in","items":[1,2,3]}'
918+
assert pred.model_dump_json() == '{"term":"foo","type":"in","values":[1,2,3]}'
919919

920920

921921
def test_serialize_not_in() -> None:
922922
pred = NotIn(term="foo", literals=[1, 2, 3])
923-
assert pred.model_dump_json() == '{"term":"foo","type":"not-in","items":[1,2,3]}'
923+
assert pred.model_dump_json() == '{"term":"foo","type":"not-in","values":[1,2,3]}'
924924

925925

926926
def test_bound_equal_to(term: BoundReference) -> None:

0 commit comments

Comments
 (0)