jerryshao commented on code in PR #9127:
URL: https://github.com/apache/gravitino/pull/9127#discussion_r2780646449


##########
lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/gravitino/GravitinoLanceTableOperations.java:
##########
@@ -301,6 +319,118 @@ public DropTableResponse dropTable(String tableId, String 
delimiter) {
     return response;
   }
 
+  @Override
+  public Object alterTable(String tableId, String delimiter, Object request) {
+    ObjectIdentifier nsId = ObjectIdentifier.of(tableId, 
Pattern.quote(delimiter));
+    Preconditions.checkArgument(
+        nsId.levels() == 3, "Expected at 3-level namespace but got: %s", 
nsId.levels());
+
+    String catalogName = nsId.levelAtListPos(0);
+    Catalog catalog = 
namespaceWrapper.loadAndValidateLakehouseCatalog(catalogName);
+    NameIdentifier tableIdentifier =
+        NameIdentifier.of(nsId.levelAtListPos(1), nsId.levelAtListPos(2));
+
+    TableAlterHandler<Object, Object> handler = getHandler(request.getClass());
+    if (handler == null) {
+      throw new IllegalArgumentException(
+          "Unsupported alter table request type: " + 
request.getClass().getName());
+    }
+    TableChange[] changes = handler.buildGravitinoTableChange(request);
+
+    Table table = catalog.asTableCatalog().alterTable(tableIdentifier, 
changes);
+
+    return handler.handle(table, request);
+  }
+
+  @SuppressWarnings("unchecked")
+  private static <REQUEST, RESPONSE> TableAlterHandler<REQUEST, RESPONSE> 
getHandler(
+      Class<?> requestClass) {
+    return (TableAlterHandler<REQUEST, RESPONSE>) 
ALTER_HANDLERS.get(requestClass);
+  }
+
+  interface TableAlterHandler<REQUEST, RESPONSE> {
+    TableChange[] buildGravitinoTableChange(REQUEST request);
+
+    RESPONSE handle(Table gravitinoTable, REQUEST request);
+  }
+
+  @VisibleForTesting
+  public static class DropColumns
+      implements TableAlterHandler<AlterTableDropColumnsRequest, 
AlterTableDropColumnsResponse> {
+
+    @Override
+    public TableChange[] 
buildGravitinoTableChange(AlterTableDropColumnsRequest request) {
+      return request.getColumns().stream()
+          .map(colName -> TableChange.deleteColumn(new String[] {colName}, 
false))
+          .toArray(TableChange[]::new);
+    }
+
+    @Override
+    public AlterTableDropColumnsResponse handle(
+        Table gravitinoTable, AlterTableDropColumnsRequest request) {
+      AlterTableDropColumnsResponse response = new 
AlterTableDropColumnsResponse();
+      Long version = extractTableVersion(gravitinoTable);
+      if (version != null) {
+        response.setVersion(version);
+      }
+      return response;
+    }
+  }
+
+  @VisibleForTesting
+  public static class AlterColumns

Review Comment:
   I suggest move these classes out of here to make the code more clear.



-- 
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