yuqi1129 commented on code in PR #12383:
URL: https://github.com/apache/gravitino/pull/12383#discussion_r3755079419


##########
catalogs/catalog-lakehouse-generic/src/main/java/org/apache/gravitino/catalog/lakehouse/lance/LanceTableOperations.java:
##########
@@ -301,9 +307,29 @@ public Table createTable(
   @Override
   public Table alterTable(NameIdentifier ident, TableChange... changes)
       throws NoSuchSchemaException, TableAlreadyExistsException {
+    List<Field> fieldsToAdd = prepareFieldsToAdd(changes);
+    if (!fieldsToAdd.isEmpty()) {
+      // AddColumn must use the same schema hydration as loadTable. A declared 
table, or a
+      // registered table with empty stored columns, may already have a real 
schema in Lance.
+      loadTable(ident);
+    }
+
+    // Schema hydration may update the entity store, so use a fresh entity 
both to validate the
+    // physical schema and as the optimistic-lock snapshot for the metadata 
update.
+    TableEntity loadedEntity = loadTableEntity(ident);
+    Table loadedTable = toGenericTable(loadedEntity);
+    validateFieldsToAdd(loadedTable, fieldsToAdd);
+    long version = handleLanceTableChange(loadedTable, changes, fieldsToAdd);
+
+    if (!fieldsToAdd.isEmpty()) {
+      try {
+        return persistAddedColumns(ident, loadedEntity, changes, version);
+      } catch (RuntimeException metadataFailure) {
+        rollbackAddedColumns(loadedTable, fieldsToAdd, metadataFailure);

Review Comment:
   Would you roll back the column created in the Lance dataset when writing 
column information fails?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to