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

Fix InMemoryCatalog Catalog commit operation #470

Merged
merged 1 commit into from
Feb 26, 2024
Merged
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
41 changes: 10 additions & 31 deletions tests/catalog/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@
SetCurrentSchemaUpdate,
Table,
TableIdentifier,
update_table_metadata,
)
from pyiceberg.table.metadata import TableMetadata, TableMetadataV1, new_table_metadata
from pyiceberg.table.metadata import TableMetadataV1
from pyiceberg.table.sorting import UNSORTED_SORT_ORDER, SortOrder
from pyiceberg.transforms import IdentityTransform
from pyiceberg.typedef import EMPTY_DICT
Expand Down Expand Up @@ -118,36 +119,13 @@ def register_table(self, identifier: Union[str, Identifier], metadata_location:
raise NotImplementedError

def _commit_table(self, table_request: CommitTableRequest) -> CommitTableResponse:
new_metadata: Optional[TableMetadata] = None
metadata_location = ""
for update in table_request.updates:
if isinstance(update, AddSchemaUpdate):
add_schema_update: AddSchemaUpdate = update
identifier = tuple(table_request.identifier.namespace.root) + (table_request.identifier.name,)
table = self.__tables[identifier]
new_metadata = new_table_metadata(
add_schema_update.schema_,
table.metadata.partition_specs[0],
table.sort_order(),
table.location(),
table.properties,
table.metadata.table_uuid,
)

table = Table(
identifier=identifier,
metadata=new_metadata,
metadata_location=f's3://warehouse/{"/".join(identifier)}/metadata/metadata.json',
io=load_file_io(),
catalog=self,
)

self.__tables[identifier] = table
metadata_location = f's3://warehouse/{"/".join(identifier)}/metadata/metadata.json'
identifier = tuple(table_request.identifier.namespace.root) + (table_request.identifier.name,)
table = self.__tables[identifier]
table.metadata = update_table_metadata(base_metadata=table.metadata, updates=table_request.updates)

return CommitTableResponse(
metadata=new_metadata.model_dump() if new_metadata else {},
metadata_location=metadata_location if metadata_location else "",
metadata=table.metadata.model_dump(),
metadata_location=table.location(),
)

def load_table(self, identifier: Union[str, Identifier]) -> Table:
Expand Down Expand Up @@ -617,8 +595,9 @@ def test_commit_table(catalog: InMemoryCatalog) -> None:

# Then
assert response.metadata.table_uuid == given_table.metadata.table_uuid
assert len(response.metadata.schemas) == 1
assert response.metadata.schemas[0] == new_schema
assert len(response.metadata.schemas) == 2
assert response.metadata.schemas[1] == new_schema
assert response.metadata.current_schema_id == new_schema.schema_id


def test_add_column(catalog: InMemoryCatalog) -> None:
Expand Down