You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "caican00 (via GitHub)" <gi...@apache.org> on 2024/08/04 13:46:25 UTC

[PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

caican00 opened a new pull request, #4349:
URL: https://github.com/apache/gravitino/pull/4349

   ### What changes were proposed in this pull request?
   
   Support alter table for Paimon Catalog.
   
   ### Why are the changes needed?
   
   Fix: https://github.com/apache/gravitino/issues/3916
   
   ### Does this PR introduce _any_ user-facing change?
   No.
   
   ### How was this patch tested?
   New UTs and ITs.
   


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "caican00 (via GitHub)" <gi...@apache.org>.
caican00 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1705068513


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TableOpsUtils.java:
##########
@@ -18,20 +18,127 @@
  */
 package org.apache.gravitino.catalog.lakehouse.paimon.utils;
 
+import static org.apache.gravitino.catalog.lakehouse.paimon.PaimonTablePropertiesMetadata.COMMENT;
+import static org.apache.gravitino.catalog.lakehouse.paimon.PaimonTablePropertiesMetadata.checkReservedProperties;
+import static org.apache.gravitino.catalog.lakehouse.paimon.utils.TypeUtils.toPaimonType;
+import static org.apache.paimon.schema.SchemaChange.addColumn;
+import static org.apache.paimon.schema.SchemaChange.dropColumn;
+import static org.apache.paimon.schema.SchemaChange.removeOption;
+import static org.apache.paimon.schema.SchemaChange.renameColumn;
+import static org.apache.paimon.schema.SchemaChange.setOption;
+import static org.apache.paimon.schema.SchemaChange.updateColumnComment;
+import static org.apache.paimon.schema.SchemaChange.updateColumnNullability;
+import static org.apache.paimon.schema.SchemaChange.updateColumnPosition;
+import static org.apache.paimon.schema.SchemaChange.updateColumnType;
+import static org.apache.paimon.schema.SchemaChange.updateComment;
+
+import com.google.common.base.Joiner;
 import com.google.common.base.Preconditions;
+import java.util.ArrayList;
+import java.util.List;
 import org.apache.gravitino.catalog.lakehouse.paimon.ops.PaimonCatalogOps;
 import org.apache.gravitino.rel.Column;
+import org.apache.gravitino.rel.TableChange;
+import org.apache.gravitino.rel.TableChange.AddColumn;
+import org.apache.gravitino.rel.TableChange.After;
+import org.apache.gravitino.rel.TableChange.ColumnChange;
+import org.apache.gravitino.rel.TableChange.ColumnPosition;
+import org.apache.gravitino.rel.TableChange.Default;
+import org.apache.gravitino.rel.TableChange.DeleteColumn;
+import org.apache.gravitino.rel.TableChange.First;
+import org.apache.gravitino.rel.TableChange.RemoveProperty;
+import org.apache.gravitino.rel.TableChange.RenameColumn;
+import org.apache.gravitino.rel.TableChange.SetProperty;
+import org.apache.gravitino.rel.TableChange.UpdateColumnComment;
+import org.apache.gravitino.rel.TableChange.UpdateColumnNullability;
+import org.apache.gravitino.rel.TableChange.UpdateColumnPosition;
+import org.apache.gravitino.rel.TableChange.UpdateColumnType;
+import org.apache.gravitino.rel.TableChange.UpdateComment;
 import org.apache.gravitino.rel.expressions.Expression;
+import org.apache.paimon.schema.SchemaChange;
+import org.apache.paimon.schema.SchemaChange.Move;
 
 /** Utilities of {@link PaimonCatalogOps} to support table operation. */
 public class TableOpsUtils {
 
+  public static final Joiner DOT = Joiner.on(".");
+
   public static void checkColumnCapability(
       String fieldName, Expression defaultValue, boolean autoIncrement) {
     checkColumnDefaultValue(fieldName, defaultValue);
     checkColumnAutoIncrement(fieldName, autoIncrement);
   }
 
+  public static List<SchemaChange> buildSchemaChanges(TableChange... tableChanges)
+      throws UnsupportedOperationException {
+    List<SchemaChange> schemaChanges = new ArrayList<>();
+    for (TableChange tableChange : tableChanges) {
+      schemaChanges.add(buildSchemaChange(tableChange));
+    }
+    return schemaChanges;
+  }
+
+  public static SchemaChange buildSchemaChange(TableChange tableChange)
+      throws UnsupportedOperationException {
+    if (tableChange instanceof ColumnChange) {
+      String[] fieldNames = ((ColumnChange) tableChange).fieldName();
+      checkNestedColumn(fieldNames);
+
+      if (tableChange instanceof AddColumn) {
+        AddColumn addColumn = (AddColumn) tableChange;
+        String fieldName = fieldName(addColumn);
+        checkColumnCapability(fieldName, addColumn.getDefaultValue(), addColumn.isAutoIncrement());
+        return addColumn(
+            fieldName,
+            toPaimonType(addColumn.getDataType()).copy(addColumn.isNullable()),
+            addColumn.getComment(),
+            move(fieldName, addColumn.getPosition()));
+      } else if (tableChange instanceof DeleteColumn) {
+        return dropColumn(fieldName((DeleteColumn) tableChange));

Review Comment:
   update



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1703515449


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TableOpsUtils.java:
##########
@@ -46,4 +153,39 @@ private static void checkColumnAutoIncrement(String fieldName, boolean autoIncre
         String.format(
             "Paimon does not support auto increment column. Illegal column: %s.", fieldName));
   }
+
+  private static void checkNestedColumn(String[] fieldNames) {
+    Preconditions.checkArgument(
+        fieldNames.length == 1,
+        String.format(
+            "Paimon does not support update nested column. Illegal column: %s.",
+            fieldName(fieldNames)));
+  }
+
+  public static String[] fieldName(String fieldName) {
+    return new String[] {fieldName};
+  }
+
+  public static String fieldName(String[] fieldName) {
+    return DOT.join(fieldName);
+  }
+
+  private static String fieldName(ColumnChange columnChange) {
+    return fieldName(columnChange.fieldName());
+  }
+
+  private static Move move(String fieldName, ColumnPosition columnPosition)
+      throws UnsupportedOperationException {
+    if (columnPosition instanceof After) {
+      return Move.after(fieldName, ((After) columnPosition).getColumn());
+    } else if (columnPosition instanceof Default) {
+      return null;

Review Comment:
   does this acttly works? seems `testUpdateColumnPosition` not cover this case.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1707235856


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TableOpsUtils.java:
##########
@@ -18,20 +18,124 @@
  */
 package org.apache.gravitino.catalog.lakehouse.paimon.utils;
 
+import static org.apache.gravitino.catalog.lakehouse.paimon.PaimonTablePropertiesMetadata.COMMENT;
+import static org.apache.gravitino.catalog.lakehouse.paimon.utils.TypeUtils.toPaimonType;
+import static org.apache.paimon.schema.SchemaChange.addColumn;
+import static org.apache.paimon.schema.SchemaChange.dropColumn;
+import static org.apache.paimon.schema.SchemaChange.removeOption;
+import static org.apache.paimon.schema.SchemaChange.renameColumn;
+import static org.apache.paimon.schema.SchemaChange.setOption;
+import static org.apache.paimon.schema.SchemaChange.updateColumnComment;
+import static org.apache.paimon.schema.SchemaChange.updateColumnNullability;
+import static org.apache.paimon.schema.SchemaChange.updateColumnPosition;
+import static org.apache.paimon.schema.SchemaChange.updateColumnType;
+import static org.apache.paimon.schema.SchemaChange.updateComment;
+
+import com.google.common.base.Joiner;
 import com.google.common.base.Preconditions;
+import java.util.ArrayList;
+import java.util.List;
 import org.apache.gravitino.catalog.lakehouse.paimon.ops.PaimonCatalogOps;
 import org.apache.gravitino.rel.Column;
+import org.apache.gravitino.rel.TableChange;
+import org.apache.gravitino.rel.TableChange.AddColumn;
+import org.apache.gravitino.rel.TableChange.After;
+import org.apache.gravitino.rel.TableChange.ColumnChange;
+import org.apache.gravitino.rel.TableChange.ColumnPosition;
+import org.apache.gravitino.rel.TableChange.Default;
+import org.apache.gravitino.rel.TableChange.DeleteColumn;
+import org.apache.gravitino.rel.TableChange.First;
+import org.apache.gravitino.rel.TableChange.RemoveProperty;
+import org.apache.gravitino.rel.TableChange.RenameColumn;
+import org.apache.gravitino.rel.TableChange.SetProperty;
+import org.apache.gravitino.rel.TableChange.UpdateColumnComment;
+import org.apache.gravitino.rel.TableChange.UpdateColumnNullability;
+import org.apache.gravitino.rel.TableChange.UpdateColumnPosition;
+import org.apache.gravitino.rel.TableChange.UpdateColumnType;
+import org.apache.gravitino.rel.TableChange.UpdateComment;
 import org.apache.gravitino.rel.expressions.Expression;
+import org.apache.paimon.schema.SchemaChange;
+import org.apache.paimon.schema.SchemaChange.Move;
 
 /** Utilities of {@link PaimonCatalogOps} to support table operation. */
 public class TableOpsUtils {
 
+  public static final Joiner DOT = Joiner.on(".");
+
   public static void checkColumnCapability(
       String fieldName, Expression defaultValue, boolean autoIncrement) {
     checkColumnDefaultValue(fieldName, defaultValue);
     checkColumnAutoIncrement(fieldName, autoIncrement);
   }
 
+  public static List<SchemaChange> buildSchemaChanges(TableChange... tableChanges)
+      throws UnsupportedOperationException {
+    List<SchemaChange> schemaChanges = new ArrayList<>();
+    for (TableChange tableChange : tableChanges) {
+      schemaChanges.add(buildSchemaChange(tableChange));
+    }
+    return schemaChanges;
+  }
+
+  public static SchemaChange buildSchemaChange(TableChange tableChange)
+      throws UnsupportedOperationException {
+    if (tableChange instanceof ColumnChange) {
+      if (tableChange instanceof AddColumn) {
+        AddColumn addColumn = (AddColumn) tableChange;
+        String fieldName = getfieldName(addColumn);
+        checkColumnCapability(fieldName, addColumn.getDefaultValue(), addColumn.isAutoIncrement());
+        return addColumn(
+            fieldName,
+            toPaimonType(addColumn.getDataType()).copy(addColumn.isNullable()),
+            addColumn.getComment(),
+            move(fieldName, addColumn.getPosition()));
+      } else if (tableChange instanceof DeleteColumn) {
+        return dropColumn(getfieldName((DeleteColumn) tableChange));
+      } else if (tableChange instanceof RenameColumn) {
+        RenameColumn renameColumn = ((RenameColumn) tableChange);
+        return renameColumn(getfieldName(renameColumn), renameColumn.getNewName());
+      } else if (tableChange instanceof UpdateColumnComment) {
+        UpdateColumnComment updateColumnComment = (UpdateColumnComment) tableChange;
+        return updateColumnComment(
+            getfieldName(updateColumnComment), updateColumnComment.getNewComment());
+      } else if (tableChange instanceof UpdateColumnNullability) {
+        UpdateColumnNullability updateColumnNullability = (UpdateColumnNullability) tableChange;
+        return updateColumnNullability(
+            getfieldName(updateColumnNullability), updateColumnNullability.nullable());
+      } else if (tableChange instanceof UpdateColumnPosition) {
+        UpdateColumnPosition updateColumnPosition = (UpdateColumnPosition) tableChange;
+        Preconditions.checkArgument(
+            !(updateColumnPosition.getPosition() instanceof Default),
+            "Default position is not supported for Paimon update column position.");
+        return updateColumnPosition(
+            move(getfieldName(updateColumnPosition), updateColumnPosition.getPosition()));
+      } else if (tableChange instanceof UpdateColumnType) {
+        UpdateColumnType updateColumnType = (UpdateColumnType) tableChange;
+        return updateColumnType(
+            getfieldName(updateColumnType), toPaimonType(updateColumnType.getNewDataType()));
+      }
+    } else if (tableChange instanceof UpdateComment) {
+      return updateComment(((UpdateComment) tableChange).getNewComment());
+    } else if (tableChange instanceof SetProperty) {
+      SetProperty setProperty = ((SetProperty) tableChange);
+      String setPropertyKey = setProperty.getProperty();
+      if (COMMENT.equals(setPropertyKey)) {

Review Comment:
   please remove the `comment` logic in `SetProperty` and `RemoveProperty`



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "caican00 (via GitHub)" <gi...@apache.org>.
caican00 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1706733694


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/PaimonTablePropertiesMetadata.java:
##########
@@ -35,15 +35,26 @@
 public class PaimonTablePropertiesMetadata extends BasePropertiesMetadata {
 
   public static final String COMMENT = "comment";
-  public static final String CREATOR = "creator";
+  public static final String OWNER = "owner";
+  public static final String BUCKET_KEY = "bucket-key";
+  public static final String MERGE_ENGINE = "merge-engine";
+  public static final String SEQUENCE_FIELD = "sequence.field";
+  public static final String ROWKIND_FIELD = "rowkind.field";
+  public static final String PRIMARY_KEY = "primary-key";
+  public static final String PARTITION = "partition";
 
   private static final Map<String, PropertyEntry<?>> PROPERTIES_METADATA;
 
   static {
     List<PropertyEntry<?>> propertyEntries =
         ImmutableList.of(
-            stringReservedPropertyEntry(COMMENT, "The table comment", true),

Review Comment:
   if the key of SetProperty is `COMMENT`,  `updateComment`  works. cc @FANNG1 



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "caican00 (via GitHub)" <gi...@apache.org>.
caican00 commented on PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#issuecomment-2273194757

   @FANNG1 could you help review again? Thanks!


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#issuecomment-2274846292

   @caican00 , could you related add docs to Paimon?


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "caican00 (via GitHub)" <gi...@apache.org>.
caican00 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1706475075


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/PaimonTablePropertiesMetadata.java:
##########
@@ -35,15 +35,26 @@
 public class PaimonTablePropertiesMetadata extends BasePropertiesMetadata {
 
   public static final String COMMENT = "comment";
-  public static final String CREATOR = "creator";
+  public static final String OWNER = "owner";
+  public static final String BUCKET_KEY = "bucket-key";
+  public static final String MERGE_ENGINE = "merge-engine";
+  public static final String SEQUENCE_FIELD = "sequence.field";
+  public static final String ROWKIND_FIELD = "rowkind.field";
+  public static final String PRIMARY_KEY = "primary-key";
+  public static final String PARTITION = "partition";
 
   private static final Map<String, PropertyEntry<?>> PROPERTIES_METADATA;
 
   static {
     List<PropertyEntry<?>> propertyEntries =
         ImmutableList.of(
-            stringReservedPropertyEntry(COMMENT, "The table comment", true),

Review Comment:
   the `COMMENT` property can be updated, i removed it from reserved Properties.
   in Paimon, the `CREATOR` should be `OWNER`, i updated it.
   cc @FANNG1 



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "caican00 (via GitHub)" <gi...@apache.org>.
caican00 commented on PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#issuecomment-2270617335

   ![image](https://github.com/user-attachments/assets/caceeef4-b2d0-43de-a57c-a69580b13f3b)
   tested IT locally.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#issuecomment-2272590837

   LGTM except minor comments


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "caican00 (via GitHub)" <gi...@apache.org>.
caican00 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1706733694


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/PaimonTablePropertiesMetadata.java:
##########
@@ -35,15 +35,26 @@
 public class PaimonTablePropertiesMetadata extends BasePropertiesMetadata {
 
   public static final String COMMENT = "comment";
-  public static final String CREATOR = "creator";
+  public static final String OWNER = "owner";
+  public static final String BUCKET_KEY = "bucket-key";
+  public static final String MERGE_ENGINE = "merge-engine";
+  public static final String SEQUENCE_FIELD = "sequence.field";
+  public static final String ROWKIND_FIELD = "rowkind.field";
+  public static final String PRIMARY_KEY = "primary-key";
+  public static final String PARTITION = "partition";
 
   private static final Map<String, PropertyEntry<?>> PROPERTIES_METADATA;
 
   static {
     List<PropertyEntry<?>> propertyEntries =
         ImmutableList.of(
-            stringReservedPropertyEntry(COMMENT, "The table comment", true),

Review Comment:
   if the key of SetProperty is `COMMENT`,  `updateComment`  works. cc @FANNG1 
   https://github.com/apache/gravitino/pull/4349/files#diff-b62c5285d8d09b282ef7a8ef2ac26d687e82dc7864dfb07c5f395b432f509dcaR122-R124



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "caican00 (via GitHub)" <gi...@apache.org>.
caican00 commented on PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#issuecomment-2274850057

   > @caican00 , could you related add docs to Paimon?
   
   @FANNG1 yeah, i am doing it. 


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1703515007


##########
catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TestTableOpsUtils.java:
##########
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.catalog.lakehouse.paimon.utils;
+
+import static org.apache.gravitino.catalog.lakehouse.paimon.utils.TableOpsUtils.buildSchemaChange;
+import static org.apache.gravitino.catalog.lakehouse.paimon.utils.TableOpsUtils.fieldName;
+import static org.apache.gravitino.rel.TableChange.ColumnPosition.after;
+import static org.apache.gravitino.rel.TableChange.ColumnPosition.defaultPos;
+import static org.apache.gravitino.rel.TableChange.addColumn;
+import static org.apache.gravitino.rel.TableChange.addIndex;
+import static org.apache.gravitino.rel.TableChange.deleteColumn;
+import static org.apache.gravitino.rel.TableChange.deleteIndex;
+import static org.apache.gravitino.rel.TableChange.removeProperty;
+import static org.apache.gravitino.rel.TableChange.rename;
+import static org.apache.gravitino.rel.TableChange.renameColumn;
+import static org.apache.gravitino.rel.TableChange.setProperty;
+import static org.apache.gravitino.rel.TableChange.updateColumnAutoIncrement;
+import static org.apache.gravitino.rel.TableChange.updateColumnComment;
+import static org.apache.gravitino.rel.TableChange.updateColumnDefaultValue;
+import static org.apache.gravitino.rel.TableChange.updateColumnNullability;
+import static org.apache.gravitino.rel.TableChange.updateColumnPosition;
+import static org.apache.gravitino.rel.TableChange.updateColumnType;
+import static org.apache.gravitino.rel.TableChange.updateComment;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Arrays;
+import java.util.function.Consumer;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.gravitino.rel.TableChange;
+import org.apache.gravitino.rel.expressions.literals.Literals;
+import org.apache.gravitino.rel.indexes.Index.IndexType;
+import org.apache.gravitino.rel.types.Types;
+import org.apache.gravitino.rel.types.Types.DoubleType;
+import org.apache.gravitino.rel.types.Types.FloatType;
+import org.apache.gravitino.rel.types.Types.IntegerType;
+import org.apache.gravitino.rel.types.Types.ListType;
+import org.apache.gravitino.rel.types.Types.MapType;
+import org.apache.gravitino.rel.types.Types.StringType;
+import org.apache.paimon.schema.SchemaChange;
+import org.apache.paimon.schema.SchemaChange.AddColumn;
+import org.apache.paimon.schema.SchemaChange.DropColumn;
+import org.apache.paimon.schema.SchemaChange.Move.MoveType;
+import org.apache.paimon.schema.SchemaChange.RemoveOption;
+import org.apache.paimon.schema.SchemaChange.RenameColumn;
+import org.apache.paimon.schema.SchemaChange.SetOption;
+import org.apache.paimon.schema.SchemaChange.UpdateColumnComment;
+import org.apache.paimon.schema.SchemaChange.UpdateColumnNullability;
+import org.apache.paimon.schema.SchemaChange.UpdateColumnPosition;
+import org.apache.paimon.schema.SchemaChange.UpdateColumnType;
+import org.apache.paimon.schema.SchemaChange.UpdateComment;
+import org.apache.paimon.types.DataTypeRoot;
+import org.junit.jupiter.api.Test;
+
+public class TestTableOpsUtils {
+
+  @Test
+  void testBuildSchemaChange() {
+    // Test supported table changes.
+    assertTableChange(
+        addColumn(
+            fieldName("col_1"),
+            IntegerType.get(),
+            AddColumn.class.getSimpleName(),
+            TableChange.ColumnPosition.first(),
+            false,
+            false),
+        AddColumn.class,
+        schemaChange -> {
+          AddColumn addColumn = (AddColumn) schemaChange;
+          assertEquals("col_1", addColumn.fieldName());
+          assertEquals(DataTypeRoot.INTEGER, addColumn.dataType().getTypeRoot());
+          assertEquals(AddColumn.class.getSimpleName(), addColumn.description());
+          assertNotNull(addColumn.move());
+          assertEquals(MoveType.FIRST, addColumn.move().type());
+          assertEquals("col_1", addColumn.move().fieldName());
+          assertNull(addColumn.move().referenceFieldName());
+          assertFalse(addColumn.dataType().isNullable());
+        });
+    assertTableChange(

Review Comment:
   could you split the test to make it 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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1706685916


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/PaimonTablePropertiesMetadata.java:
##########
@@ -35,15 +35,26 @@
 public class PaimonTablePropertiesMetadata extends BasePropertiesMetadata {
 
   public static final String COMMENT = "comment";
-  public static final String CREATOR = "creator";
+  public static final String OWNER = "owner";
+  public static final String BUCKET_KEY = "bucket-key";
+  public static final String MERGE_ENGINE = "merge-engine";
+  public static final String SEQUENCE_FIELD = "sequence.field";
+  public static final String ROWKIND_FIELD = "rowkind.field";
+  public static final String PRIMARY_KEY = "primary-key";
+  public static final String PARTITION = "partition";
 
   private static final Map<String, PropertyEntry<?>> PROPERTIES_METADATA;
 
   static {
     List<PropertyEntry<?>> propertyEntries =
         ImmutableList.of(
-            stringReservedPropertyEntry(COMMENT, "The table comment", true),

Review Comment:
   COMMENT should be updated with `updateComment` not `setProperties`



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1706965109


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/PaimonTablePropertiesMetadata.java:
##########
@@ -35,15 +35,26 @@
 public class PaimonTablePropertiesMetadata extends BasePropertiesMetadata {
 
   public static final String COMMENT = "comment";
-  public static final String CREATOR = "creator";
+  public static final String OWNER = "owner";
+  public static final String BUCKET_KEY = "bucket-key";
+  public static final String MERGE_ENGINE = "merge-engine";
+  public static final String SEQUENCE_FIELD = "sequence.field";
+  public static final String ROWKIND_FIELD = "rowkind.field";
+  public static final String PRIMARY_KEY = "primary-key";
+  public static final String PARTITION = "partition";
 
   private static final Map<String, PropertyEntry<?>> PROPERTIES_METADATA;
 
   static {
     List<PropertyEntry<?>> propertyEntries =
         ImmutableList.of(
-            stringReservedPropertyEntry(COMMENT, "The table comment", true),

Review Comment:
   I think we shouldn't allow user pass 'comment' properties as Gravitino provides `updateComment` interface



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "caican00 (via GitHub)" <gi...@apache.org>.
caican00 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1706997856


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/PaimonTablePropertiesMetadata.java:
##########
@@ -35,15 +35,26 @@
 public class PaimonTablePropertiesMetadata extends BasePropertiesMetadata {
 
   public static final String COMMENT = "comment";
-  public static final String CREATOR = "creator";
+  public static final String OWNER = "owner";
+  public static final String BUCKET_KEY = "bucket-key";
+  public static final String MERGE_ENGINE = "merge-engine";
+  public static final String SEQUENCE_FIELD = "sequence.field";
+  public static final String ROWKIND_FIELD = "rowkind.field";
+  public static final String PRIMARY_KEY = "primary-key";
+  public static final String PARTITION = "partition";
 
   private static final Map<String, PropertyEntry<?>> PROPERTIES_METADATA;
 
   static {
     List<PropertyEntry<?>> propertyEntries =
         ImmutableList.of(
-            stringReservedPropertyEntry(COMMENT, "The table comment", true),

Review Comment:
   ok, updated.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1706347712


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TableOpsUtils.java:
##########
@@ -18,20 +18,125 @@
  */
 package org.apache.gravitino.catalog.lakehouse.paimon.utils;
 
+import static org.apache.gravitino.catalog.lakehouse.paimon.PaimonTablePropertiesMetadata.COMMENT;
+import static org.apache.gravitino.catalog.lakehouse.paimon.utils.TypeUtils.toPaimonType;
+import static org.apache.paimon.schema.SchemaChange.addColumn;
+import static org.apache.paimon.schema.SchemaChange.dropColumn;
+import static org.apache.paimon.schema.SchemaChange.removeOption;
+import static org.apache.paimon.schema.SchemaChange.renameColumn;
+import static org.apache.paimon.schema.SchemaChange.setOption;
+import static org.apache.paimon.schema.SchemaChange.updateColumnComment;
+import static org.apache.paimon.schema.SchemaChange.updateColumnNullability;
+import static org.apache.paimon.schema.SchemaChange.updateColumnPosition;
+import static org.apache.paimon.schema.SchemaChange.updateColumnType;
+import static org.apache.paimon.schema.SchemaChange.updateComment;
+
+import com.google.common.base.Joiner;
 import com.google.common.base.Preconditions;
+import java.util.ArrayList;
+import java.util.List;
 import org.apache.gravitino.catalog.lakehouse.paimon.ops.PaimonCatalogOps;
 import org.apache.gravitino.rel.Column;
+import org.apache.gravitino.rel.TableChange;
+import org.apache.gravitino.rel.TableChange.AddColumn;
+import org.apache.gravitino.rel.TableChange.After;
+import org.apache.gravitino.rel.TableChange.ColumnChange;
+import org.apache.gravitino.rel.TableChange.ColumnPosition;
+import org.apache.gravitino.rel.TableChange.Default;
+import org.apache.gravitino.rel.TableChange.DeleteColumn;
+import org.apache.gravitino.rel.TableChange.First;
+import org.apache.gravitino.rel.TableChange.RemoveProperty;
+import org.apache.gravitino.rel.TableChange.RenameColumn;
+import org.apache.gravitino.rel.TableChange.SetProperty;
+import org.apache.gravitino.rel.TableChange.UpdateColumnComment;
+import org.apache.gravitino.rel.TableChange.UpdateColumnNullability;
+import org.apache.gravitino.rel.TableChange.UpdateColumnPosition;
+import org.apache.gravitino.rel.TableChange.UpdateColumnType;
+import org.apache.gravitino.rel.TableChange.UpdateComment;
 import org.apache.gravitino.rel.expressions.Expression;
+import org.apache.paimon.schema.SchemaChange;
+import org.apache.paimon.schema.SchemaChange.Move;
 
 /** Utilities of {@link PaimonCatalogOps} to support table operation. */
 public class TableOpsUtils {
 
+  public static final Joiner DOT = Joiner.on(".");
+
   public static void checkColumnCapability(
       String fieldName, Expression defaultValue, boolean autoIncrement) {
     checkColumnDefaultValue(fieldName, defaultValue);
     checkColumnAutoIncrement(fieldName, autoIncrement);
   }
 
+  public static List<SchemaChange> buildSchemaChanges(TableChange... tableChanges)
+      throws UnsupportedOperationException {
+    List<SchemaChange> schemaChanges = new ArrayList<>();
+    for (TableChange tableChange : tableChanges) {
+      schemaChanges.add(buildSchemaChange(tableChange));
+    }
+    return schemaChanges;
+  }
+
+  public static SchemaChange buildSchemaChange(TableChange tableChange)
+      throws UnsupportedOperationException {
+    if (tableChange instanceof ColumnChange) {
+

Review Comment:
   please remove empty line



##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/PaimonTablePropertiesMetadata.java:
##########
@@ -35,15 +35,26 @@
 public class PaimonTablePropertiesMetadata extends BasePropertiesMetadata {
 
   public static final String COMMENT = "comment";
-  public static final String CREATOR = "creator";
+  public static final String OWNER = "owner";
+  public static final String BUCKET_KEY = "bucket-key";
+  public static final String MERGE_ENGINE = "merge-engine";
+  public static final String SEQUENCE_FIELD = "sequence.field";
+  public static final String ROWKIND_FIELD = "rowkind.field";
+  public static final String PRIMARY_KEY = "primary-key";
+  public static final String PARTITION = "partition";
 
   private static final Map<String, PropertyEntry<?>> PROPERTIES_METADATA;
 
   static {
     List<PropertyEntry<?>> propertyEntries =
         ImmutableList.of(
-            stringReservedPropertyEntry(COMMENT, "The table comment", true),

Review Comment:
   why remove COMMENT and CREATOR?



##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TableOpsUtils.java:
##########
@@ -46,4 +153,39 @@ private static void checkColumnAutoIncrement(String fieldName, boolean autoIncre
         String.format(
             "Paimon does not support auto increment column. Illegal column: %s.", fieldName));
   }
+
+  private static void checkNestedColumn(String[] fieldNames) {
+    Preconditions.checkArgument(
+        fieldNames.length == 1,
+        String.format(
+            "Paimon does not support update nested column. Illegal column: %s.",
+            fieldName(fieldNames)));
+  }
+
+  public static String[] fieldName(String fieldName) {
+    return new String[] {fieldName};
+  }
+
+  public static String fieldName(String[] fieldName) {
+    return DOT.join(fieldName);
+  }
+
+  private static String fieldName(ColumnChange columnChange) {
+    return fieldName(columnChange.fieldName());
+  }
+
+  private static Move move(String fieldName, ColumnPosition columnPosition)
+      throws UnsupportedOperationException {
+    if (columnPosition instanceof After) {
+      return Move.after(fieldName, ((After) columnPosition).getColumn());
+    } else if (columnPosition instanceof Default) {
+      return null;

Review Comment:
   Iceberg did some logic when updateColumnPosition is `default`, but this seems ridiculous after another thought, tracked in #4412 



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "caican00 (via GitHub)" <gi...@apache.org>.
caican00 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1706997856


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/PaimonTablePropertiesMetadata.java:
##########
@@ -35,15 +35,26 @@
 public class PaimonTablePropertiesMetadata extends BasePropertiesMetadata {
 
   public static final String COMMENT = "comment";
-  public static final String CREATOR = "creator";
+  public static final String OWNER = "owner";
+  public static final String BUCKET_KEY = "bucket-key";
+  public static final String MERGE_ENGINE = "merge-engine";
+  public static final String SEQUENCE_FIELD = "sequence.field";
+  public static final String ROWKIND_FIELD = "rowkind.field";
+  public static final String PRIMARY_KEY = "primary-key";
+  public static final String PARTITION = "partition";
 
   private static final Map<String, PropertyEntry<?>> PROPERTIES_METADATA;
 
   static {
     List<PropertyEntry<?>> propertyEntries =
         ImmutableList.of(
-            stringReservedPropertyEntry(COMMENT, "The table comment", true),

Review Comment:
   ok



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "caican00 (via GitHub)" <gi...@apache.org>.
caican00 commented on PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#issuecomment-2268016478

   CC @FANNG1 


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "caican00 (via GitHub)" <gi...@apache.org>.
caican00 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1705045203


##########
catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TestTableOpsUtils.java:
##########
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.catalog.lakehouse.paimon.utils;
+
+import static org.apache.gravitino.catalog.lakehouse.paimon.utils.TableOpsUtils.buildSchemaChange;
+import static org.apache.gravitino.catalog.lakehouse.paimon.utils.TableOpsUtils.fieldName;
+import static org.apache.gravitino.rel.TableChange.ColumnPosition.after;
+import static org.apache.gravitino.rel.TableChange.ColumnPosition.defaultPos;
+import static org.apache.gravitino.rel.TableChange.addColumn;
+import static org.apache.gravitino.rel.TableChange.addIndex;
+import static org.apache.gravitino.rel.TableChange.deleteColumn;
+import static org.apache.gravitino.rel.TableChange.deleteIndex;
+import static org.apache.gravitino.rel.TableChange.removeProperty;
+import static org.apache.gravitino.rel.TableChange.rename;
+import static org.apache.gravitino.rel.TableChange.renameColumn;
+import static org.apache.gravitino.rel.TableChange.setProperty;
+import static org.apache.gravitino.rel.TableChange.updateColumnAutoIncrement;
+import static org.apache.gravitino.rel.TableChange.updateColumnComment;
+import static org.apache.gravitino.rel.TableChange.updateColumnDefaultValue;
+import static org.apache.gravitino.rel.TableChange.updateColumnNullability;
+import static org.apache.gravitino.rel.TableChange.updateColumnPosition;
+import static org.apache.gravitino.rel.TableChange.updateColumnType;
+import static org.apache.gravitino.rel.TableChange.updateComment;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Arrays;
+import java.util.function.Consumer;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.gravitino.rel.TableChange;
+import org.apache.gravitino.rel.expressions.literals.Literals;
+import org.apache.gravitino.rel.indexes.Index.IndexType;
+import org.apache.gravitino.rel.types.Types;
+import org.apache.gravitino.rel.types.Types.DoubleType;
+import org.apache.gravitino.rel.types.Types.FloatType;
+import org.apache.gravitino.rel.types.Types.IntegerType;
+import org.apache.gravitino.rel.types.Types.ListType;
+import org.apache.gravitino.rel.types.Types.MapType;
+import org.apache.gravitino.rel.types.Types.StringType;
+import org.apache.paimon.schema.SchemaChange;
+import org.apache.paimon.schema.SchemaChange.AddColumn;
+import org.apache.paimon.schema.SchemaChange.DropColumn;
+import org.apache.paimon.schema.SchemaChange.Move.MoveType;
+import org.apache.paimon.schema.SchemaChange.RemoveOption;
+import org.apache.paimon.schema.SchemaChange.RenameColumn;
+import org.apache.paimon.schema.SchemaChange.SetOption;
+import org.apache.paimon.schema.SchemaChange.UpdateColumnComment;
+import org.apache.paimon.schema.SchemaChange.UpdateColumnNullability;
+import org.apache.paimon.schema.SchemaChange.UpdateColumnPosition;
+import org.apache.paimon.schema.SchemaChange.UpdateColumnType;
+import org.apache.paimon.schema.SchemaChange.UpdateComment;
+import org.apache.paimon.types.DataTypeRoot;
+import org.junit.jupiter.api.Test;
+
+public class TestTableOpsUtils {
+
+  @Test
+  void testBuildSchemaChange() {
+    // Test supported table changes.
+    assertTableChange(
+        addColumn(
+            fieldName("col_1"),
+            IntegerType.get(),
+            AddColumn.class.getSimpleName(),
+            TableChange.ColumnPosition.first(),
+            false,
+            false),
+        AddColumn.class,
+        schemaChange -> {
+          AddColumn addColumn = (AddColumn) schemaChange;
+          assertEquals("col_1", addColumn.fieldName());
+          assertEquals(DataTypeRoot.INTEGER, addColumn.dataType().getTypeRoot());
+          assertEquals(AddColumn.class.getSimpleName(), addColumn.description());
+          assertNotNull(addColumn.move());
+          assertEquals(MoveType.FIRST, addColumn.move().type());
+          assertEquals("col_1", addColumn.move().fieldName());
+          assertNull(addColumn.move().referenceFieldName());
+          assertFalse(addColumn.dataType().isNullable());
+        });
+    assertTableChange(

Review Comment:
   updated.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "caican00 (via GitHub)" <gi...@apache.org>.
caican00 commented on PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#issuecomment-2270618513

   comments have been addressed, could you help review again? @FANNG1 


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "caican00 (via GitHub)" <gi...@apache.org>.
caican00 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1708397726


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/PaimonTablePropertiesMetadata.java:
##########
@@ -35,15 +35,27 @@
 public class PaimonTablePropertiesMetadata extends BasePropertiesMetadata {
 
   public static final String COMMENT = "comment";
-  public static final String CREATOR = "creator";
+  public static final String OWNER = "owner";
+  public static final String BUCKET_KEY = "bucket-key";
+  public static final String MERGE_ENGINE = "merge-engine";
+  public static final String SEQUENCE_FIELD = "sequence.field";
+  public static final String ROWKIND_FIELD = "rowkind.field";
+  public static final String PRIMARY_KEY = "primary-key";
+  public static final String PARTITION = "partition";
 
   private static final Map<String, PropertyEntry<?>> PROPERTIES_METADATA;
 
   static {
     List<PropertyEntry<?>> propertyEntries =
         ImmutableList.of(
-            stringReservedPropertyEntry(COMMENT, "The table comment", true),

Review Comment:
   updated.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "caican00 (via GitHub)" <gi...@apache.org>.
caican00 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1706475075


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/PaimonTablePropertiesMetadata.java:
##########
@@ -35,15 +35,26 @@
 public class PaimonTablePropertiesMetadata extends BasePropertiesMetadata {
 
   public static final String COMMENT = "comment";
-  public static final String CREATOR = "creator";
+  public static final String OWNER = "owner";
+  public static final String BUCKET_KEY = "bucket-key";
+  public static final String MERGE_ENGINE = "merge-engine";
+  public static final String SEQUENCE_FIELD = "sequence.field";
+  public static final String ROWKIND_FIELD = "rowkind.field";
+  public static final String PRIMARY_KEY = "primary-key";
+  public static final String PARTITION = "partition";
 
   private static final Map<String, PropertyEntry<?>> PROPERTIES_METADATA;
 
   static {
     List<PropertyEntry<?>> propertyEntries =
         ImmutableList.of(
-            stringReservedPropertyEntry(COMMENT, "The table comment", true),

Review Comment:
   the `COMMENT` property can be updated, i removed it from reserved Properties.
   in Paimon, the `CREATOR` should be `OWNER`, i updated it.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "caican00 (via GitHub)" <gi...@apache.org>.
caican00 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1706480010


##########
catalogs/catalog-lakehouse-paimon/build.gradle.kts:
##########
@@ -138,7 +138,7 @@ tasks.test {
     dependsOn(tasks.jar)
 
     doFirst {
-      environment("GRAVITINO_CI_HIVE_DOCKER_IMAGE", "datastrato/gravitino-ci-hive:0.1.13")
+      environment("GRAVITINO_CI_HIVE_DOCKER_IMAGE", "datastrato/gravitino-ci-hive:0.1.12")

Review Comment:
   update.



##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TableOpsUtils.java:
##########
@@ -18,20 +18,125 @@
  */
 package org.apache.gravitino.catalog.lakehouse.paimon.utils;
 
+import static org.apache.gravitino.catalog.lakehouse.paimon.PaimonTablePropertiesMetadata.COMMENT;
+import static org.apache.gravitino.catalog.lakehouse.paimon.utils.TypeUtils.toPaimonType;
+import static org.apache.paimon.schema.SchemaChange.addColumn;
+import static org.apache.paimon.schema.SchemaChange.dropColumn;
+import static org.apache.paimon.schema.SchemaChange.removeOption;
+import static org.apache.paimon.schema.SchemaChange.renameColumn;
+import static org.apache.paimon.schema.SchemaChange.setOption;
+import static org.apache.paimon.schema.SchemaChange.updateColumnComment;
+import static org.apache.paimon.schema.SchemaChange.updateColumnNullability;
+import static org.apache.paimon.schema.SchemaChange.updateColumnPosition;
+import static org.apache.paimon.schema.SchemaChange.updateColumnType;
+import static org.apache.paimon.schema.SchemaChange.updateComment;
+
+import com.google.common.base.Joiner;
 import com.google.common.base.Preconditions;
+import java.util.ArrayList;
+import java.util.List;
 import org.apache.gravitino.catalog.lakehouse.paimon.ops.PaimonCatalogOps;
 import org.apache.gravitino.rel.Column;
+import org.apache.gravitino.rel.TableChange;
+import org.apache.gravitino.rel.TableChange.AddColumn;
+import org.apache.gravitino.rel.TableChange.After;
+import org.apache.gravitino.rel.TableChange.ColumnChange;
+import org.apache.gravitino.rel.TableChange.ColumnPosition;
+import org.apache.gravitino.rel.TableChange.Default;
+import org.apache.gravitino.rel.TableChange.DeleteColumn;
+import org.apache.gravitino.rel.TableChange.First;
+import org.apache.gravitino.rel.TableChange.RemoveProperty;
+import org.apache.gravitino.rel.TableChange.RenameColumn;
+import org.apache.gravitino.rel.TableChange.SetProperty;
+import org.apache.gravitino.rel.TableChange.UpdateColumnComment;
+import org.apache.gravitino.rel.TableChange.UpdateColumnNullability;
+import org.apache.gravitino.rel.TableChange.UpdateColumnPosition;
+import org.apache.gravitino.rel.TableChange.UpdateColumnType;
+import org.apache.gravitino.rel.TableChange.UpdateComment;
 import org.apache.gravitino.rel.expressions.Expression;
+import org.apache.paimon.schema.SchemaChange;
+import org.apache.paimon.schema.SchemaChange.Move;
 
 /** Utilities of {@link PaimonCatalogOps} to support table operation. */
 public class TableOpsUtils {
 
+  public static final Joiner DOT = Joiner.on(".");
+
   public static void checkColumnCapability(
       String fieldName, Expression defaultValue, boolean autoIncrement) {
     checkColumnDefaultValue(fieldName, defaultValue);
     checkColumnAutoIncrement(fieldName, autoIncrement);
   }
 
+  public static List<SchemaChange> buildSchemaChanges(TableChange... tableChanges)
+      throws UnsupportedOperationException {
+    List<SchemaChange> schemaChanges = new ArrayList<>();
+    for (TableChange tableChange : tableChanges) {
+      schemaChanges.add(buildSchemaChange(tableChange));
+    }
+    return schemaChanges;
+  }
+
+  public static SchemaChange buildSchemaChange(TableChange tableChange)
+      throws UnsupportedOperationException {
+    if (tableChange instanceof ColumnChange) {
+

Review Comment:
   update



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "caican00 (via GitHub)" <gi...@apache.org>.
caican00 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1706740125


##########
catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/TestGravitinoPaimonTable.java:
##########
@@ -383,8 +383,13 @@ void testTableProperty() {
       ops.initialize(
           initBackendCatalogProperties(), entity.toCatalogInfo(), PAIMON_PROPERTIES_METADATA);
       Map<String, String> map = Maps.newHashMap();
-      map.put(PaimonTablePropertiesMetadata.COMMENT, "test");

Review Comment:
   ok, updated.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1708247151


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/PaimonTablePropertiesMetadata.java:
##########
@@ -35,15 +35,27 @@
 public class PaimonTablePropertiesMetadata extends BasePropertiesMetadata {
 
   public static final String COMMENT = "comment";
-  public static final String CREATOR = "creator";
+  public static final String OWNER = "owner";
+  public static final String BUCKET_KEY = "bucket-key";
+  public static final String MERGE_ENGINE = "merge-engine";
+  public static final String SEQUENCE_FIELD = "sequence.field";
+  public static final String ROWKIND_FIELD = "rowkind.field";
+  public static final String PRIMARY_KEY = "primary-key";
+  public static final String PARTITION = "partition";
 
   private static final Map<String, PropertyEntry<?>> PROPERTIES_METADATA;
 
   static {
     List<PropertyEntry<?>> propertyEntries =
         ImmutableList.of(
-            stringReservedPropertyEntry(COMMENT, "The table comment", true),

Review Comment:
   better to keep `COMMENT` hidden



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "caican00 (via GitHub)" <gi...@apache.org>.
caican00 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1706336082


##########
catalogs/catalog-lakehouse-paimon/build.gradle.kts:
##########
@@ -138,7 +138,7 @@ tasks.test {
     dependsOn(tasks.jar)
 
     doFirst {
-      environment("GRAVITINO_CI_HIVE_DOCKER_IMAGE", "datastrato/gravitino-ci-hive:0.1.13")
+      environment("GRAVITINO_CI_HIVE_DOCKER_IMAGE", "datastrato/gravitino-ci-hive:0.1.12")

Review Comment:
   will roll it back.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "caican00 (via GitHub)" <gi...@apache.org>.
caican00 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1704828729


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TableOpsUtils.java:
##########
@@ -46,4 +153,39 @@ private static void checkColumnAutoIncrement(String fieldName, boolean autoIncre
         String.format(
             "Paimon does not support auto increment column. Illegal column: %s.", fieldName));
   }
+
+  private static void checkNestedColumn(String[] fieldNames) {
+    Preconditions.checkArgument(
+        fieldNames.length == 1,
+        String.format(
+            "Paimon does not support update nested column. Illegal column: %s.",
+            fieldName(fieldNames)));
+  }
+
+  public static String[] fieldName(String fieldName) {
+    return new String[] {fieldName};
+  }
+
+  public static String fieldName(String[] fieldName) {
+    return DOT.join(fieldName);
+  }
+
+  private static String fieldName(ColumnChange columnChange) {
+    return fieldName(columnChange.fieldName());
+  }
+
+  private static Move move(String fieldName, ColumnPosition columnPosition)
+      throws UnsupportedOperationException {
+    if (columnPosition instanceof After) {
+      return Move.after(fieldName, ((After) columnPosition).getColumn());
+    } else if (columnPosition instanceof Default) {
+      return null;

Review Comment:
   1. for `AddColumn` in Paimon: https://github.com/apache/paimon/blob/master/paimon-core/src/main/java/org/apache/paimon/schema/SchemaManager.java#L245-L254
   if the Move is null, then the new column will be added  to the end.
   
   2. `Default` position is not supported for `UpdateColumnPosition` in Paimon



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "caican00 (via GitHub)" <gi...@apache.org>.
caican00 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1705075869


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TableOpsUtils.java:
##########
@@ -46,4 +153,39 @@ private static void checkColumnAutoIncrement(String fieldName, boolean autoIncre
         String.format(
             "Paimon does not support auto increment column. Illegal column: %s.", fieldName));
   }
+
+  private static void checkNestedColumn(String[] fieldNames) {
+    Preconditions.checkArgument(
+        fieldNames.length == 1,
+        String.format(
+            "Paimon does not support update nested column. Illegal column: %s.",
+            fieldName(fieldNames)));
+  }
+
+  public static String[] fieldName(String fieldName) {
+    return new String[] {fieldName};
+  }
+
+  public static String fieldName(String[] fieldName) {
+    return DOT.join(fieldName);
+  }
+
+  private static String fieldName(ColumnChange columnChange) {
+    return fieldName(columnChange.fieldName());
+  }
+
+  private static Move move(String fieldName, ColumnPosition columnPosition)
+      throws UnsupportedOperationException {
+    if (columnPosition instanceof After) {
+      return Move.after(fieldName, ((After) columnPosition).getColumn());
+    } else if (columnPosition instanceof Default) {
+      return null;

Review Comment:
   > does this acttly works
   
   https://github.com/apache/gravitino/pull/4349/files#diff-6bea46f4cb01e05fd11727d1fddd956728bcb163d08f4be08d39ee7eeb729b9fR532-R533
   there is a test case about `AddColumn` with `Default` position.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1703513023


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TableOpsUtils.java:
##########
@@ -18,20 +18,127 @@
  */
 package org.apache.gravitino.catalog.lakehouse.paimon.utils;
 
+import static org.apache.gravitino.catalog.lakehouse.paimon.PaimonTablePropertiesMetadata.COMMENT;
+import static org.apache.gravitino.catalog.lakehouse.paimon.PaimonTablePropertiesMetadata.checkReservedProperties;
+import static org.apache.gravitino.catalog.lakehouse.paimon.utils.TypeUtils.toPaimonType;
+import static org.apache.paimon.schema.SchemaChange.addColumn;
+import static org.apache.paimon.schema.SchemaChange.dropColumn;
+import static org.apache.paimon.schema.SchemaChange.removeOption;
+import static org.apache.paimon.schema.SchemaChange.renameColumn;
+import static org.apache.paimon.schema.SchemaChange.setOption;
+import static org.apache.paimon.schema.SchemaChange.updateColumnComment;
+import static org.apache.paimon.schema.SchemaChange.updateColumnNullability;
+import static org.apache.paimon.schema.SchemaChange.updateColumnPosition;
+import static org.apache.paimon.schema.SchemaChange.updateColumnType;
+import static org.apache.paimon.schema.SchemaChange.updateComment;
+
+import com.google.common.base.Joiner;
 import com.google.common.base.Preconditions;
+import java.util.ArrayList;
+import java.util.List;
 import org.apache.gravitino.catalog.lakehouse.paimon.ops.PaimonCatalogOps;
 import org.apache.gravitino.rel.Column;
+import org.apache.gravitino.rel.TableChange;
+import org.apache.gravitino.rel.TableChange.AddColumn;
+import org.apache.gravitino.rel.TableChange.After;
+import org.apache.gravitino.rel.TableChange.ColumnChange;
+import org.apache.gravitino.rel.TableChange.ColumnPosition;
+import org.apache.gravitino.rel.TableChange.Default;
+import org.apache.gravitino.rel.TableChange.DeleteColumn;
+import org.apache.gravitino.rel.TableChange.First;
+import org.apache.gravitino.rel.TableChange.RemoveProperty;
+import org.apache.gravitino.rel.TableChange.RenameColumn;
+import org.apache.gravitino.rel.TableChange.SetProperty;
+import org.apache.gravitino.rel.TableChange.UpdateColumnComment;
+import org.apache.gravitino.rel.TableChange.UpdateColumnNullability;
+import org.apache.gravitino.rel.TableChange.UpdateColumnPosition;
+import org.apache.gravitino.rel.TableChange.UpdateColumnType;
+import org.apache.gravitino.rel.TableChange.UpdateComment;
 import org.apache.gravitino.rel.expressions.Expression;
+import org.apache.paimon.schema.SchemaChange;
+import org.apache.paimon.schema.SchemaChange.Move;
 
 /** Utilities of {@link PaimonCatalogOps} to support table operation. */
 public class TableOpsUtils {
 
+  public static final Joiner DOT = Joiner.on(".");
+
   public static void checkColumnCapability(
       String fieldName, Expression defaultValue, boolean autoIncrement) {
     checkColumnDefaultValue(fieldName, defaultValue);
     checkColumnAutoIncrement(fieldName, autoIncrement);
   }
 
+  public static List<SchemaChange> buildSchemaChanges(TableChange... tableChanges)
+      throws UnsupportedOperationException {
+    List<SchemaChange> schemaChanges = new ArrayList<>();
+    for (TableChange tableChange : tableChanges) {
+      schemaChanges.add(buildSchemaChange(tableChange));
+    }
+    return schemaChanges;
+  }
+
+  public static SchemaChange buildSchemaChange(TableChange tableChange)
+      throws UnsupportedOperationException {
+    if (tableChange instanceof ColumnChange) {
+      String[] fieldNames = ((ColumnChange) tableChange).fieldName();
+      checkNestedColumn(fieldNames);
+
+      if (tableChange instanceof AddColumn) {
+        AddColumn addColumn = (AddColumn) tableChange;
+        String fieldName = fieldName(addColumn);
+        checkColumnCapability(fieldName, addColumn.getDefaultValue(), addColumn.isAutoIncrement());
+        return addColumn(
+            fieldName,
+            toPaimonType(addColumn.getDataType()).copy(addColumn.isNullable()),
+            addColumn.getComment(),
+            move(fieldName, addColumn.getPosition()));
+      } else if (tableChange instanceof DeleteColumn) {
+        return dropColumn(fieldName((DeleteColumn) tableChange));
+      } else if (tableChange instanceof RenameColumn) {
+        RenameColumn renameColumn = ((RenameColumn) tableChange);
+        return renameColumn(fieldName(renameColumn), renameColumn.getNewName());
+      } else if (tableChange instanceof UpdateColumnComment) {
+        UpdateColumnComment updateColumnComment = (UpdateColumnComment) tableChange;
+        return updateColumnComment(
+            fieldName(updateColumnComment), updateColumnComment.getNewComment());
+      } else if (tableChange instanceof UpdateColumnNullability) {
+        UpdateColumnNullability updateColumnNullability = (UpdateColumnNullability) tableChange;
+        return updateColumnNullability(
+            fieldName(updateColumnNullability), updateColumnNullability.nullable());
+      } else if (tableChange instanceof UpdateColumnPosition) {
+        UpdateColumnPosition updateColumnPosition = (UpdateColumnPosition) tableChange;
+        return updateColumnPosition(
+            move(fieldName(updateColumnPosition), updateColumnPosition.getPosition()));
+      } else if (tableChange instanceof UpdateColumnType) {
+        UpdateColumnType updateColumnType = (UpdateColumnType) tableChange;
+        return updateColumnType(
+            fieldName(updateColumnType), toPaimonType(updateColumnType.getNewDataType()));
+      }
+    } else if (tableChange instanceof UpdateComment) {
+      return updateComment(((UpdateComment) tableChange).getNewComment());
+    } else if (tableChange instanceof SetProperty) {
+      SetProperty setProperty = ((SetProperty) tableChange);
+      String setPropertyKey = setProperty.getProperty();
+      checkReservedProperties(setPropertyKey);

Review Comment:
   reserved properties are not allowed to alter, no need to check again



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "caican00 (via GitHub)" <gi...@apache.org>.
caican00 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1707257378


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TableOpsUtils.java:
##########
@@ -18,20 +18,124 @@
  */
 package org.apache.gravitino.catalog.lakehouse.paimon.utils;
 
+import static org.apache.gravitino.catalog.lakehouse.paimon.PaimonTablePropertiesMetadata.COMMENT;
+import static org.apache.gravitino.catalog.lakehouse.paimon.utils.TypeUtils.toPaimonType;
+import static org.apache.paimon.schema.SchemaChange.addColumn;
+import static org.apache.paimon.schema.SchemaChange.dropColumn;
+import static org.apache.paimon.schema.SchemaChange.removeOption;
+import static org.apache.paimon.schema.SchemaChange.renameColumn;
+import static org.apache.paimon.schema.SchemaChange.setOption;
+import static org.apache.paimon.schema.SchemaChange.updateColumnComment;
+import static org.apache.paimon.schema.SchemaChange.updateColumnNullability;
+import static org.apache.paimon.schema.SchemaChange.updateColumnPosition;
+import static org.apache.paimon.schema.SchemaChange.updateColumnType;
+import static org.apache.paimon.schema.SchemaChange.updateComment;
+
+import com.google.common.base.Joiner;
 import com.google.common.base.Preconditions;
+import java.util.ArrayList;
+import java.util.List;
 import org.apache.gravitino.catalog.lakehouse.paimon.ops.PaimonCatalogOps;
 import org.apache.gravitino.rel.Column;
+import org.apache.gravitino.rel.TableChange;
+import org.apache.gravitino.rel.TableChange.AddColumn;
+import org.apache.gravitino.rel.TableChange.After;
+import org.apache.gravitino.rel.TableChange.ColumnChange;
+import org.apache.gravitino.rel.TableChange.ColumnPosition;
+import org.apache.gravitino.rel.TableChange.Default;
+import org.apache.gravitino.rel.TableChange.DeleteColumn;
+import org.apache.gravitino.rel.TableChange.First;
+import org.apache.gravitino.rel.TableChange.RemoveProperty;
+import org.apache.gravitino.rel.TableChange.RenameColumn;
+import org.apache.gravitino.rel.TableChange.SetProperty;
+import org.apache.gravitino.rel.TableChange.UpdateColumnComment;
+import org.apache.gravitino.rel.TableChange.UpdateColumnNullability;
+import org.apache.gravitino.rel.TableChange.UpdateColumnPosition;
+import org.apache.gravitino.rel.TableChange.UpdateColumnType;
+import org.apache.gravitino.rel.TableChange.UpdateComment;
 import org.apache.gravitino.rel.expressions.Expression;
+import org.apache.paimon.schema.SchemaChange;
+import org.apache.paimon.schema.SchemaChange.Move;
 
 /** Utilities of {@link PaimonCatalogOps} to support table operation. */
 public class TableOpsUtils {
 
+  public static final Joiner DOT = Joiner.on(".");
+
   public static void checkColumnCapability(
       String fieldName, Expression defaultValue, boolean autoIncrement) {
     checkColumnDefaultValue(fieldName, defaultValue);
     checkColumnAutoIncrement(fieldName, autoIncrement);
   }
 
+  public static List<SchemaChange> buildSchemaChanges(TableChange... tableChanges)
+      throws UnsupportedOperationException {
+    List<SchemaChange> schemaChanges = new ArrayList<>();
+    for (TableChange tableChange : tableChanges) {
+      schemaChanges.add(buildSchemaChange(tableChange));
+    }
+    return schemaChanges;
+  }
+
+  public static SchemaChange buildSchemaChange(TableChange tableChange)
+      throws UnsupportedOperationException {
+    if (tableChange instanceof ColumnChange) {
+      if (tableChange instanceof AddColumn) {
+        AddColumn addColumn = (AddColumn) tableChange;
+        String fieldName = getfieldName(addColumn);
+        checkColumnCapability(fieldName, addColumn.getDefaultValue(), addColumn.isAutoIncrement());
+        return addColumn(
+            fieldName,
+            toPaimonType(addColumn.getDataType()).copy(addColumn.isNullable()),
+            addColumn.getComment(),
+            move(fieldName, addColumn.getPosition()));
+      } else if (tableChange instanceof DeleteColumn) {
+        return dropColumn(getfieldName((DeleteColumn) tableChange));
+      } else if (tableChange instanceof RenameColumn) {
+        RenameColumn renameColumn = ((RenameColumn) tableChange);
+        return renameColumn(getfieldName(renameColumn), renameColumn.getNewName());
+      } else if (tableChange instanceof UpdateColumnComment) {
+        UpdateColumnComment updateColumnComment = (UpdateColumnComment) tableChange;
+        return updateColumnComment(
+            getfieldName(updateColumnComment), updateColumnComment.getNewComment());
+      } else if (tableChange instanceof UpdateColumnNullability) {
+        UpdateColumnNullability updateColumnNullability = (UpdateColumnNullability) tableChange;
+        return updateColumnNullability(
+            getfieldName(updateColumnNullability), updateColumnNullability.nullable());
+      } else if (tableChange instanceof UpdateColumnPosition) {
+        UpdateColumnPosition updateColumnPosition = (UpdateColumnPosition) tableChange;
+        Preconditions.checkArgument(
+            !(updateColumnPosition.getPosition() instanceof Default),
+            "Default position is not supported for Paimon update column position.");
+        return updateColumnPosition(
+            move(getfieldName(updateColumnPosition), updateColumnPosition.getPosition()));
+      } else if (tableChange instanceof UpdateColumnType) {
+        UpdateColumnType updateColumnType = (UpdateColumnType) tableChange;
+        return updateColumnType(
+            getfieldName(updateColumnType), toPaimonType(updateColumnType.getNewDataType()));
+      }
+    } else if (tableChange instanceof UpdateComment) {
+      return updateComment(((UpdateComment) tableChange).getNewComment());
+    } else if (tableChange instanceof SetProperty) {
+      SetProperty setProperty = ((SetProperty) tableChange);
+      String setPropertyKey = setProperty.getProperty();
+      if (COMMENT.equals(setPropertyKey)) {

Review Comment:
   done



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1703495556


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/PaimonCatalogOperations.java:
##########
@@ -457,4 +482,52 @@ private NameIdentifier buildPaimonNameIdentifier(NameIdentifier identifier) {
     String[] levels = identifier.namespace().levels();
     return NameIdentifier.of(levels[levels.length - 1], identifier.name());
   }
+
+  /**
+   * Performs rename table change with the provided identifier.
+   *
+   * @param identifier The identifier of the table to rename.
+   * @param renameTable Table Change to modify the table name.
+   * @return The renamed {@link GravitinoPaimonTable} instance.
+   * @throws NoSuchTableException If the table with the provided identifier does not exist.
+   * @throws IllegalArgumentException This exception will not be thrown in this method.
+   */
+  private GravitinoPaimonTable renameTable(
+      NameIdentifier identifier, TableChange.RenameTable renameTable)
+      throws NoSuchTableException, IllegalArgumentException {
+    try {
+      paimonCatalogOps.renameTable(
+          identifier.toString(),
+          NameIdentifier.of(identifier.namespace(), renameTable.getNewName()).toString());
+    } catch (Catalog.TableNotExistException e) {
+      throw new NoSuchTableException(e, NO_SUCH_TABLE_EXCEPTION, identifier);
+    } catch (Catalog.TableAlreadyExistException e) {
+      throw new TableAlreadyExistsException(e, TABLE_ALREADY_EXISTS_EXCEPTION, identifier);

Review Comment:
   use newTable name not original table name?



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1703513403


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TableOpsUtils.java:
##########
@@ -18,20 +18,127 @@
  */
 package org.apache.gravitino.catalog.lakehouse.paimon.utils;
 
+import static org.apache.gravitino.catalog.lakehouse.paimon.PaimonTablePropertiesMetadata.COMMENT;
+import static org.apache.gravitino.catalog.lakehouse.paimon.PaimonTablePropertiesMetadata.checkReservedProperties;
+import static org.apache.gravitino.catalog.lakehouse.paimon.utils.TypeUtils.toPaimonType;
+import static org.apache.paimon.schema.SchemaChange.addColumn;
+import static org.apache.paimon.schema.SchemaChange.dropColumn;
+import static org.apache.paimon.schema.SchemaChange.removeOption;
+import static org.apache.paimon.schema.SchemaChange.renameColumn;
+import static org.apache.paimon.schema.SchemaChange.setOption;
+import static org.apache.paimon.schema.SchemaChange.updateColumnComment;
+import static org.apache.paimon.schema.SchemaChange.updateColumnNullability;
+import static org.apache.paimon.schema.SchemaChange.updateColumnPosition;
+import static org.apache.paimon.schema.SchemaChange.updateColumnType;
+import static org.apache.paimon.schema.SchemaChange.updateComment;
+
+import com.google.common.base.Joiner;
 import com.google.common.base.Preconditions;
+import java.util.ArrayList;
+import java.util.List;
 import org.apache.gravitino.catalog.lakehouse.paimon.ops.PaimonCatalogOps;
 import org.apache.gravitino.rel.Column;
+import org.apache.gravitino.rel.TableChange;
+import org.apache.gravitino.rel.TableChange.AddColumn;
+import org.apache.gravitino.rel.TableChange.After;
+import org.apache.gravitino.rel.TableChange.ColumnChange;
+import org.apache.gravitino.rel.TableChange.ColumnPosition;
+import org.apache.gravitino.rel.TableChange.Default;
+import org.apache.gravitino.rel.TableChange.DeleteColumn;
+import org.apache.gravitino.rel.TableChange.First;
+import org.apache.gravitino.rel.TableChange.RemoveProperty;
+import org.apache.gravitino.rel.TableChange.RenameColumn;
+import org.apache.gravitino.rel.TableChange.SetProperty;
+import org.apache.gravitino.rel.TableChange.UpdateColumnComment;
+import org.apache.gravitino.rel.TableChange.UpdateColumnNullability;
+import org.apache.gravitino.rel.TableChange.UpdateColumnPosition;
+import org.apache.gravitino.rel.TableChange.UpdateColumnType;
+import org.apache.gravitino.rel.TableChange.UpdateComment;
 import org.apache.gravitino.rel.expressions.Expression;
+import org.apache.paimon.schema.SchemaChange;
+import org.apache.paimon.schema.SchemaChange.Move;
 
 /** Utilities of {@link PaimonCatalogOps} to support table operation. */
 public class TableOpsUtils {
 
+  public static final Joiner DOT = Joiner.on(".");
+
   public static void checkColumnCapability(
       String fieldName, Expression defaultValue, boolean autoIncrement) {
     checkColumnDefaultValue(fieldName, defaultValue);
     checkColumnAutoIncrement(fieldName, autoIncrement);
   }
 
+  public static List<SchemaChange> buildSchemaChanges(TableChange... tableChanges)
+      throws UnsupportedOperationException {
+    List<SchemaChange> schemaChanges = new ArrayList<>();
+    for (TableChange tableChange : tableChanges) {
+      schemaChanges.add(buildSchemaChange(tableChange));
+    }
+    return schemaChanges;
+  }
+
+  public static SchemaChange buildSchemaChange(TableChange tableChange)
+      throws UnsupportedOperationException {
+    if (tableChange instanceof ColumnChange) {
+      String[] fieldNames = ((ColumnChange) tableChange).fieldName();
+      checkNestedColumn(fieldNames);
+
+      if (tableChange instanceof AddColumn) {
+        AddColumn addColumn = (AddColumn) tableChange;
+        String fieldName = fieldName(addColumn);
+        checkColumnCapability(fieldName, addColumn.getDefaultValue(), addColumn.isAutoIncrement());
+        return addColumn(
+            fieldName,
+            toPaimonType(addColumn.getDataType()).copy(addColumn.isNullable()),
+            addColumn.getComment(),
+            move(fieldName, addColumn.getPosition()));
+      } else if (tableChange instanceof DeleteColumn) {
+        return dropColumn(fieldName((DeleteColumn) tableChange));

Review Comment:
   fieldName -> getfieldName ?



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "caican00 (via GitHub)" <gi...@apache.org>.
caican00 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1705044809


##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/PaimonCatalogOperations.java:
##########
@@ -457,4 +482,52 @@ private NameIdentifier buildPaimonNameIdentifier(NameIdentifier identifier) {
     String[] levels = identifier.namespace().levels();
     return NameIdentifier.of(levels[levels.length - 1], identifier.name());
   }
+
+  /**
+   * Performs rename table change with the provided identifier.
+   *
+   * @param identifier The identifier of the table to rename.
+   * @param renameTable Table Change to modify the table name.
+   * @return The renamed {@link GravitinoPaimonTable} instance.
+   * @throws NoSuchTableException If the table with the provided identifier does not exist.
+   * @throws IllegalArgumentException This exception will not be thrown in this method.
+   */
+  private GravitinoPaimonTable renameTable(
+      NameIdentifier identifier, TableChange.RenameTable renameTable)
+      throws NoSuchTableException, IllegalArgumentException {
+    try {
+      paimonCatalogOps.renameTable(
+          identifier.toString(),
+          NameIdentifier.of(identifier.namespace(), renameTable.getNewName()).toString());
+    } catch (Catalog.TableNotExistException e) {
+      throw new NoSuchTableException(e, NO_SUCH_TABLE_EXCEPTION, identifier);
+    } catch (Catalog.TableAlreadyExistException e) {
+      throw new TableAlreadyExistsException(e, TABLE_ALREADY_EXISTS_EXCEPTION, identifier);

Review Comment:
   fixed



##########
catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TableOpsUtils.java:
##########
@@ -18,20 +18,127 @@
  */
 package org.apache.gravitino.catalog.lakehouse.paimon.utils;
 
+import static org.apache.gravitino.catalog.lakehouse.paimon.PaimonTablePropertiesMetadata.COMMENT;
+import static org.apache.gravitino.catalog.lakehouse.paimon.PaimonTablePropertiesMetadata.checkReservedProperties;
+import static org.apache.gravitino.catalog.lakehouse.paimon.utils.TypeUtils.toPaimonType;
+import static org.apache.paimon.schema.SchemaChange.addColumn;
+import static org.apache.paimon.schema.SchemaChange.dropColumn;
+import static org.apache.paimon.schema.SchemaChange.removeOption;
+import static org.apache.paimon.schema.SchemaChange.renameColumn;
+import static org.apache.paimon.schema.SchemaChange.setOption;
+import static org.apache.paimon.schema.SchemaChange.updateColumnComment;
+import static org.apache.paimon.schema.SchemaChange.updateColumnNullability;
+import static org.apache.paimon.schema.SchemaChange.updateColumnPosition;
+import static org.apache.paimon.schema.SchemaChange.updateColumnType;
+import static org.apache.paimon.schema.SchemaChange.updateComment;
+
+import com.google.common.base.Joiner;
 import com.google.common.base.Preconditions;
+import java.util.ArrayList;
+import java.util.List;
 import org.apache.gravitino.catalog.lakehouse.paimon.ops.PaimonCatalogOps;
 import org.apache.gravitino.rel.Column;
+import org.apache.gravitino.rel.TableChange;
+import org.apache.gravitino.rel.TableChange.AddColumn;
+import org.apache.gravitino.rel.TableChange.After;
+import org.apache.gravitino.rel.TableChange.ColumnChange;
+import org.apache.gravitino.rel.TableChange.ColumnPosition;
+import org.apache.gravitino.rel.TableChange.Default;
+import org.apache.gravitino.rel.TableChange.DeleteColumn;
+import org.apache.gravitino.rel.TableChange.First;
+import org.apache.gravitino.rel.TableChange.RemoveProperty;
+import org.apache.gravitino.rel.TableChange.RenameColumn;
+import org.apache.gravitino.rel.TableChange.SetProperty;
+import org.apache.gravitino.rel.TableChange.UpdateColumnComment;
+import org.apache.gravitino.rel.TableChange.UpdateColumnNullability;
+import org.apache.gravitino.rel.TableChange.UpdateColumnPosition;
+import org.apache.gravitino.rel.TableChange.UpdateColumnType;
+import org.apache.gravitino.rel.TableChange.UpdateComment;
 import org.apache.gravitino.rel.expressions.Expression;
+import org.apache.paimon.schema.SchemaChange;
+import org.apache.paimon.schema.SchemaChange.Move;
 
 /** Utilities of {@link PaimonCatalogOps} to support table operation. */
 public class TableOpsUtils {
 
+  public static final Joiner DOT = Joiner.on(".");
+
   public static void checkColumnCapability(
       String fieldName, Expression defaultValue, boolean autoIncrement) {
     checkColumnDefaultValue(fieldName, defaultValue);
     checkColumnAutoIncrement(fieldName, autoIncrement);
   }
 
+  public static List<SchemaChange> buildSchemaChanges(TableChange... tableChanges)
+      throws UnsupportedOperationException {
+    List<SchemaChange> schemaChanges = new ArrayList<>();
+    for (TableChange tableChange : tableChanges) {
+      schemaChanges.add(buildSchemaChange(tableChange));
+    }
+    return schemaChanges;
+  }
+
+  public static SchemaChange buildSchemaChange(TableChange tableChange)
+      throws UnsupportedOperationException {
+    if (tableChange instanceof ColumnChange) {
+      String[] fieldNames = ((ColumnChange) tableChange).fieldName();
+      checkNestedColumn(fieldNames);
+
+      if (tableChange instanceof AddColumn) {
+        AddColumn addColumn = (AddColumn) tableChange;
+        String fieldName = fieldName(addColumn);
+        checkColumnCapability(fieldName, addColumn.getDefaultValue(), addColumn.isAutoIncrement());
+        return addColumn(
+            fieldName,
+            toPaimonType(addColumn.getDataType()).copy(addColumn.isNullable()),
+            addColumn.getComment(),
+            move(fieldName, addColumn.getPosition()));
+      } else if (tableChange instanceof DeleteColumn) {
+        return dropColumn(fieldName((DeleteColumn) tableChange));
+      } else if (tableChange instanceof RenameColumn) {
+        RenameColumn renameColumn = ((RenameColumn) tableChange);
+        return renameColumn(fieldName(renameColumn), renameColumn.getNewName());
+      } else if (tableChange instanceof UpdateColumnComment) {
+        UpdateColumnComment updateColumnComment = (UpdateColumnComment) tableChange;
+        return updateColumnComment(
+            fieldName(updateColumnComment), updateColumnComment.getNewComment());
+      } else if (tableChange instanceof UpdateColumnNullability) {
+        UpdateColumnNullability updateColumnNullability = (UpdateColumnNullability) tableChange;
+        return updateColumnNullability(
+            fieldName(updateColumnNullability), updateColumnNullability.nullable());
+      } else if (tableChange instanceof UpdateColumnPosition) {
+        UpdateColumnPosition updateColumnPosition = (UpdateColumnPosition) tableChange;
+        return updateColumnPosition(
+            move(fieldName(updateColumnPosition), updateColumnPosition.getPosition()));
+      } else if (tableChange instanceof UpdateColumnType) {
+        UpdateColumnType updateColumnType = (UpdateColumnType) tableChange;
+        return updateColumnType(
+            fieldName(updateColumnType), toPaimonType(updateColumnType.getNewDataType()));
+      }
+    } else if (tableChange instanceof UpdateComment) {
+      return updateComment(((UpdateComment) tableChange).getNewComment());
+    } else if (tableChange instanceof SetProperty) {
+      SetProperty setProperty = ((SetProperty) tableChange);
+      String setPropertyKey = setProperty.getProperty();
+      checkReservedProperties(setPropertyKey);

Review Comment:
   removed



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on code in PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#discussion_r1706689454


##########
catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/TestGravitinoPaimonTable.java:
##########
@@ -383,8 +383,13 @@ void testTableProperty() {
       ops.initialize(
           initBackendCatalogProperties(), entity.toCatalogInfo(), PAIMON_PROPERTIES_METADATA);
       Map<String, String> map = Maps.newHashMap();
-      map.put(PaimonTablePropertiesMetadata.COMMENT, "test");

Review Comment:
   reserve comment here?



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 merged PR #4349:
URL: https://github.com/apache/gravitino/pull/4349


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#3916] feat(catalog-lakehouse-paimon): Support alter table for Paimon Catalog [gravitino]

Posted by "caican00 (via GitHub)" <gi...@apache.org>.
caican00 commented on PR #4349:
URL: https://github.com/apache/gravitino/pull/4349#issuecomment-2272755276

   comments have been fixed cc @FANNG1 


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org