-
Notifications
You must be signed in to change notification settings - Fork 414
fix: Validate SetStatisticsUpdate correctly (fixes #2865) #2866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,7 +21,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||
| from abc import ABC, abstractmethod | ||||||||||||||||||||||||||||||||||||||||||||||||
| from datetime import datetime | ||||||||||||||||||||||||||||||||||||||||||||||||
| from functools import singledispatch | ||||||||||||||||||||||||||||||||||||||||||||||||
| from typing import TYPE_CHECKING, Annotated, Any, Generic, Literal, TypeVar, cast | ||||||||||||||||||||||||||||||||||||||||||||||||
| from typing import TYPE_CHECKING, Annotated, Any, Generic, Literal, TypeVar | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| from pydantic import Field, field_validator, model_serializer, model_validator | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -181,9 +181,15 @@ class SetStatisticsUpdate(IcebergBaseModel): | |||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| @model_validator(mode="before") | ||||||||||||||||||||||||||||||||||||||||||||||||
| def validate_snapshot_id(cls, data: dict[str, Any]) -> dict[str, Any]: | ||||||||||||||||||||||||||||||||||||||||||||||||
| stats = cast(StatisticsFile, data["statistics"]) | ||||||||||||||||||||||||||||||||||||||||||||||||
| snapshot_id = None | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| data["snapshot_id"] = stats.snapshot_id | ||||||||||||||||||||||||||||||||||||||||||||||||
| stats = data["statistics"] | ||||||||||||||||||||||||||||||||||||||||||||||||
| if isinstance(stats, StatisticsFile): | ||||||||||||||||||||||||||||||||||||||||||||||||
| snapshot_id = stats.snapshot_id | ||||||||||||||||||||||||||||||||||||||||||||||||
| elif isinstance(stats, dict): | ||||||||||||||||||||||||||||||||||||||||||||||||
| snapshot_id = stats.get("snapshot_id") | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
i think this should be iceberg-python/pyiceberg/table/statistics.py Lines 32 to 40 in fa03e08
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you add a test case for this (and possibly one for the else case too)? The current test only test the iceberg-python/tests/table/test_init.py Lines 1370 to 1381 in fa03e08
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+189
to
+191
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
nit: i think we can inline the else here |
||||||||||||||||||||||||||||||||||||||||||||||||
| data["snapshot_id"] = snapshot_id | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| return data | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.