Skip to content

Commit 407dc14

Browse files
committed
PR fixes
1 parent 7fc25ff commit 407dc14

File tree

2 files changed

+16
-37
lines changed

2 files changed

+16
-37
lines changed

pyiceberg/catalog/rest/expression.py

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,6 @@ class Reference(IcebergRootModel[str]):
2727
root: str = Field(..., json_schema_extra={"example": "column-name"})
2828

2929

30-
class ExpressionType(IcebergRootModel[str]):
31-
root: str = Field(
32-
...,
33-
json_schema_extra={
34-
"example": [
35-
"true",
36-
"false",
37-
"eq",
38-
"and",
39-
"or",
40-
"not",
41-
"in",
42-
"not-in",
43-
"lt",
44-
"lt-eq",
45-
"gt",
46-
"gt-eq",
47-
"not-eq",
48-
"starts-with",
49-
"not-starts-with",
50-
"is-null",
51-
"not-null",
52-
"is-nan",
53-
"not-nan",
54-
]
55-
},
56-
)
57-
58-
5930
class TrueExpression(IcebergBaseModel):
6031
type: Literal["true"] = "true"
6132

@@ -75,7 +46,7 @@ class Term(IcebergRootModel[Union[Reference, TransformTerm]]):
7546

7647

7748
class AndOrExpression(IcebergBaseModel):
78-
type: ExpressionType
49+
type: Literal["and", "or"]
7950
left: "Expression"
8051
right: "Expression"
8152

@@ -86,19 +57,19 @@ class NotExpression(IcebergBaseModel):
8657

8758

8859
class SetExpression(IcebergBaseModel):
89-
type: ExpressionType
60+
type: Literal["in", "not-in"]
9061
term: Term
9162
values: List[Dict[str, Any]]
9263

9364

9465
class LiteralExpression(IcebergBaseModel):
95-
type: ExpressionType
66+
type: Literal["lt", "lt-eq", "gt", "gt-eq", "eq", "not-eq", "starts-with", "not-starts-with"]
9667
term: Term
9768
value: Dict[str, Any]
9869

9970

10071
class UnaryExpression(IcebergBaseModel):
101-
type: ExpressionType
72+
type: Literal["is-null", "not-null", "is-nan", "not-nan"]
10273
term: Term
10374
value: Dict[str, Any]
10475

tests/catalog/test_rest_serializers.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ def test_serialize_plan_table_scan_request() -> None:
6060
filter=Expression(root=expression),
6161
case_sensitive=True,
6262
)
63+
# Assert that JSON matches.
6364
assert request.model_dump_json(exclude_none=True) == snapshot_json_for_plan_table_scan_request()
6465

6566

6667
def test_deserialize_plan_table_scan_request() -> None:
67-
"""Test deserializing a PlanTableScanRequest from a dict"""
68+
"""Test deserializing a dict to a PlanTableScanRequest"""
69+
model = PlanTableScanRequest.model_validate_json(snapshot_json_for_plan_table_scan_request())
6870
expression = AndOrExpression(
6971
type="and",
7072
left=Expression(
@@ -86,18 +88,22 @@ def test_deserialize_plan_table_scan_request() -> None:
8688
),
8789
right=Expression(root=LiteralExpression(type="gt", term=Term(root="d"), value={"type": "integer", "value": 4})),
8890
)
89-
request = PlanTableScanRequest(
91+
expected = PlanTableScanRequest(
9092
snapshot_id=1,
9193
select=["a", "b", "c"],
9294
filter=Expression(root=expression),
9395
case_sensitive=True,
9496
)
95-
assert request == PlanTableScanRequest.model_validate_json(snapshot_json_for_plan_table_scan_request())
97+
98+
# Assert that deserialized dict == Python object
99+
assert model == expected
96100

97101

98102
def test_deserialize_scan_tasks() -> None:
99-
"""Test deserializing a ScanTasks from a dict"""
103+
"""Test deserializing dict to ScanTasks"""
100104
scan_tasks = ScanTasks.model_validate_json(snapshot_json_for_scan_tasks())
105+
106+
# Assert JSON fields match expected.
101107
assert len(scan_tasks.file_scan_tasks) == 1
102108
assert len(scan_tasks.delete_files) == 2
103109
assert scan_tasks.file_scan_tasks[0].data_file.file_path == "/path/to/data-a.parquet"
@@ -148,6 +154,8 @@ def test_serialize_scan_tasks() -> None:
148154
),
149155
],
150156
)
157+
158+
# Assert that JSON matches.
151159
assert scan_tasks.model_dump_json(exclude_none=True) == snapshot_json_for_scan_tasks()
152160

153161

0 commit comments

Comments
 (0)