|
52 | 52 | SetCurrentSchemaUpdate, |
53 | 53 | Table, |
54 | 54 | TableIdentifier, |
| 55 | + update_table_metadata, |
55 | 56 | ) |
56 | | -from pyiceberg.table.metadata import TableMetadata, TableMetadataV1, new_table_metadata |
| 57 | +from pyiceberg.table.metadata import TableMetadataV1 |
57 | 58 | from pyiceberg.table.sorting import UNSORTED_SORT_ORDER, SortOrder |
58 | 59 | from pyiceberg.transforms import IdentityTransform |
59 | 60 | from pyiceberg.typedef import EMPTY_DICT |
@@ -118,36 +119,13 @@ def register_table(self, identifier: Union[str, Identifier], metadata_location: |
118 | 119 | raise NotImplementedError |
119 | 120 |
|
120 | 121 | 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) |
147 | 125 |
|
148 | 126 | 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(), |
151 | 129 | ) |
152 | 130 |
|
153 | 131 | def load_table(self, identifier: Union[str, Identifier]) -> Table: |
@@ -617,8 +595,9 @@ def test_commit_table(catalog: InMemoryCatalog) -> None: |
617 | 595 |
|
618 | 596 | # Then |
619 | 597 | 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 |
622 | 601 |
|
623 | 602 |
|
624 | 603 | def test_add_column(catalog: InMemoryCatalog) -> None: |
|
0 commit comments