Skip to content

Commit 5c6010b

Browse files
authored
Use update_table_metadata in InMemory Catalog (#470)
1 parent b31922f commit 5c6010b

File tree

1 file changed

+10
-31
lines changed

1 file changed

+10
-31
lines changed

tests/catalog/test_base.py

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@
5252
SetCurrentSchemaUpdate,
5353
Table,
5454
TableIdentifier,
55+
update_table_metadata,
5556
)
56-
from pyiceberg.table.metadata import TableMetadata, TableMetadataV1, new_table_metadata
57+
from pyiceberg.table.metadata import TableMetadataV1
5758
from pyiceberg.table.sorting import UNSORTED_SORT_ORDER, SortOrder
5859
from pyiceberg.transforms import IdentityTransform
5960
from pyiceberg.typedef import EMPTY_DICT
@@ -118,36 +119,13 @@ def register_table(self, identifier: Union[str, Identifier], metadata_location:
118119
raise NotImplementedError
119120

120121
def _commit_table(self, table_request: CommitTableRequest) -> CommitTableResponse:
121-
new_metadata: Optional[TableMetadata] = None
122-
metadata_location = ""
123-
for update in table_request.updates:
124-
if isinstance(update, AddSchemaUpdate):
125-
add_schema_update: AddSchemaUpdate = update
126-
identifier = tuple(table_request.identifier.namespace.root) + (table_request.identifier.name,)
127-
table = self.__tables[identifier]
128-
new_metadata = new_table_metadata(
129-
add_schema_update.schema_,
130-
table.metadata.partition_specs[0],
131-
table.sort_order(),
132-
table.location(),
133-
table.properties,
134-
table.metadata.table_uuid,
135-
)
136-
137-
table = Table(
138-
identifier=identifier,
139-
metadata=new_metadata,
140-
metadata_location=f's3://warehouse/{"/".join(identifier)}/metadata/metadata.json',
141-
io=load_file_io(),
142-
catalog=self,
143-
)
144-
145-
self.__tables[identifier] = table
146-
metadata_location = f's3://warehouse/{"/".join(identifier)}/metadata/metadata.json'
122+
identifier = tuple(table_request.identifier.namespace.root) + (table_request.identifier.name,)
123+
table = self.__tables[identifier]
124+
table.metadata = update_table_metadata(base_metadata=table.metadata, updates=table_request.updates)
147125

148126
return CommitTableResponse(
149-
metadata=new_metadata.model_dump() if new_metadata else {},
150-
metadata_location=metadata_location if metadata_location else "",
127+
metadata=table.metadata.model_dump(),
128+
metadata_location=table.location(),
151129
)
152130

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

618596
# Then
619597
assert response.metadata.table_uuid == given_table.metadata.table_uuid
620-
assert len(response.metadata.schemas) == 1
621-
assert response.metadata.schemas[0] == new_schema
598+
assert len(response.metadata.schemas) == 2
599+
assert response.metadata.schemas[1] == new_schema
600+
assert response.metadata.current_schema_id == new_schema.schema_id
622601

623602

624603
def test_add_column(catalog: InMemoryCatalog) -> None:

0 commit comments

Comments
 (0)