Skip to content
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

Open-API: Refactor updates with discriminator #9240

Merged
merged 4 commits into from
Dec 11, 2023
Merged
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
37 changes: 18 additions & 19 deletions open-api/rest-catalog-open-api.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,40 +239,25 @@ class ViewVersion(BaseModel):


class BaseUpdate(BaseModel):
action: Literal[
'assign-uuid',
'upgrade-format-version',
'add-schema',
'set-current-schema',
'add-spec',
'set-default-spec',
'add-sort-order',
'set-default-sort-order',
'add-snapshot',
'set-snapshot-ref',
'remove-snapshots',
'remove-snapshot-ref',
'set-location',
'set-properties',
'remove-properties',
'add-view-version',
'set-current-view-version',
]
action: str


class AssignUUIDUpdate(BaseUpdate):
"""
Assigning a UUID to a table/view should only be done when creating the table/view. It is not safe to re-assign the UUID if a table/view already has a UUID assigned
"""

action: Literal['assign-uuid']
uuid: str


class UpgradeFormatVersionUpdate(BaseUpdate):
action: Literal['upgrade-format-version']
format_version: int = Field(..., alias='format-version')


class SetCurrentSchemaUpdate(BaseUpdate):
action: Literal['set-current-schema']
schema_id: int = Field(
...,
alias='schema-id',
Expand All @@ -281,10 +266,12 @@ class SetCurrentSchemaUpdate(BaseUpdate):


class AddPartitionSpecUpdate(BaseUpdate):
action: Literal['add-spec']
spec: PartitionSpec


class SetDefaultSpecUpdate(BaseUpdate):
action: Literal['set-default-spec']
spec_id: int = Field(
...,
alias='spec-id',
Expand All @@ -293,10 +280,12 @@ class SetDefaultSpecUpdate(BaseUpdate):


class AddSortOrderUpdate(BaseUpdate):
action: Literal['add-sort-order']
sort_order: SortOrder = Field(..., alias='sort-order')


class SetDefaultSortOrderUpdate(BaseUpdate):
action: Literal['set-default-sort-order']
sort_order_id: int = Field(
...,
alias='sort-order-id',
Expand All @@ -305,38 +294,47 @@ class SetDefaultSortOrderUpdate(BaseUpdate):


class AddSnapshotUpdate(BaseUpdate):
action: Literal['add-snapshot']
snapshot: Snapshot


class SetSnapshotRefUpdate(BaseUpdate, SnapshotReference):
action: Literal['set-snapshot-ref']
ref_name: str = Field(..., alias='ref-name')


class RemoveSnapshotsUpdate(BaseUpdate):
action: Literal['remove-snapshots']
snapshot_ids: List[int] = Field(..., alias='snapshot-ids')


class RemoveSnapshotRefUpdate(BaseUpdate):
action: Literal['remove-snapshot-ref']
ref_name: str = Field(..., alias='ref-name')


class SetLocationUpdate(BaseUpdate):
action: Literal['set-location']
location: str


class SetPropertiesUpdate(BaseUpdate):
action: Literal['set-properties']
updates: Dict[str, str]


class RemovePropertiesUpdate(BaseUpdate):
action: Literal['remove-properties']
removals: List[str]


class AddViewVersionUpdate(BaseUpdate):
action: Literal['add-view-version']
view_version: ViewVersion = Field(..., alias='view-version')


class SetCurrentViewVersionUpdate(BaseUpdate):
action: Literal['set-current-view-version']
view_version_id: int = Field(
...,
alias='view-version-id',
Expand Down Expand Up @@ -734,6 +732,7 @@ class ViewMetadata(BaseModel):


class AddSchemaUpdate(BaseUpdate):
action: Literal['add-schema']
schema_: Schema = Field(..., alias='schema')
last_column_id: Optional[int] = Field(
None,
Expand Down
Loading