-
Notifications
You must be signed in to change notification settings - Fork 293
Feature: Write to branches #941
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 18 commits
d4ca653
0b7aaaf
23f04ec
af6ff9a
6fbf3f1
8ce1509
6daf29e
09321cd
60fef31
45b01a6
917108b
917b044
398f6c0
b7b8ba0
ee591b4
e81907d
4cf9198
bc6fb68
82e65e1
82e5b90
84d0971
3efe53c
dfedc63
076a6d5
53a7f84
e4463df
49f75b4
4ed0607
958aac4
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 |
---|---|---|
|
@@ -29,7 +29,7 @@ | |
from pyiceberg.partitioning import PARTITION_FIELD_ID_START, PartitionSpec | ||
from pyiceberg.schema import Schema | ||
from pyiceberg.table.metadata import SUPPORTED_TABLE_FORMAT_VERSION, TableMetadata, TableMetadataUtil | ||
from pyiceberg.table.refs import MAIN_BRANCH, SnapshotRef | ||
from pyiceberg.table.refs import MAIN_BRANCH, SnapshotRef, SnapshotRefType | ||
from pyiceberg.table.snapshots import ( | ||
MetadataLogEntry, | ||
Snapshot, | ||
|
@@ -154,7 +154,7 @@ class AddSnapshotUpdate(IcebergBaseModel): | |
class SetSnapshotRefUpdate(IcebergBaseModel): | ||
action: Literal["set-snapshot-ref"] = Field(default="set-snapshot-ref") | ||
ref_name: str = Field(alias="ref-name") | ||
type: Literal["tag", "branch"] | ||
type: Literal[SnapshotRefType.TAG, SnapshotRefType.BRANCH] | ||
snapshot_id: int = Field(alias="snapshot-id") | ||
max_ref_age_ms: Annotated[Optional[int], Field(alias="max-ref-age-ms", default=None)] | ||
max_snapshot_age_ms: Annotated[Optional[int], Field(alias="max-snapshot-age-ms", default=None)] | ||
|
@@ -609,11 +609,14 @@ class AssertRefSnapshotId(ValidatableTableRequirement): | |
|
||
type: Literal["assert-ref-snapshot-id"] = Field(default="assert-ref-snapshot-id") | ||
ref: str = Field(...) | ||
ref_type: SnapshotRefType = Field(...) | ||
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. nit instead of adding this extra field, can we do something like the java side? 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. Makes sense. Let me get back on how I can introduce the change 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. 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. Resolved the comments |
||
snapshot_id: Optional[int] = Field(default=None, alias="snapshot-id") | ||
|
||
def validate(self, base_metadata: Optional[TableMetadata]) -> None: | ||
if base_metadata is None: | ||
raise CommitFailedException("Requirement failed: current table metadata is missing") | ||
elif len(base_metadata.snapshots) == 0 and self.ref != MAIN_BRANCH: | ||
raise CommitFailedException(f"Requirement failed: No snapshot available in table for ref: {self.ref}") | ||
elif snapshot_ref := base_metadata.refs.get(self.ref): | ||
ref_type = snapshot_ref.snapshot_ref_type | ||
if self.snapshot_id is None: | ||
|
@@ -622,6 +625,8 @@ def validate(self, base_metadata: Optional[TableMetadata]) -> None: | |
raise CommitFailedException( | ||
f"Requirement failed: {ref_type} {self.ref} has changed: expected id {self.snapshot_id}, found {snapshot_ref.snapshot_id}" | ||
) | ||
elif ref_type != self.ref_type: | ||
raise CommitFailedException(f"Requirement failed: {ref_type} {self.ref} can't be changed to type {self.ref_type}") | ||
elif self.snapshot_id is not None: | ||
raise CommitFailedException(f"Requirement failed: branch or tag {self.ref} is missing, expected {self.snapshot_id}") | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.