This is an automated email from the ASF dual-hosted git repository.

diqiu50 pushed a commit to branch cherry-pick-2c7c308d-to-branch-1.3
in repository https://gitbox.apache.org/repos/asf/gravitino.git

commit 4fdfe159013552cbe2f30bd79a329660aabfa8f7
Merge: 2118a08a99 6644e1618a
Author: yuhui <[email protected]>
AuthorDate: Thu Oct 22 15:05:29 2026 +0800

    Merge remote-tracking branch 'gt/branch-1.3' into 
cherry-pick-2c7c308d-to-branch-1.3
    
    # Conflicts:
    #       
catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/operation/TestMysqlTableOperations.java
    #       
catalogs/catalog-jdbc-starrocks/src/test/java/org/apache/gravitino/catalog/starrocks/operation/TestStarRocksTableOperations.java

 .../operation/OceanBaseTableOperations.java        |  3 +-
 .../operation/TestOceanBaseTableOperations.java    | 33 ++++++++++++++++++
 .../mysql/operation/MysqlTableOperations.java      |  3 +-
 .../mysql/operation/TestMysqlTableOperations.java  | 33 ++++++++++++++++++
 .../operations/StarRocksTableOperations.java       |  3 +-
 .../operation/TestStarRocksTableOperations.java    | 40 ++++++++++++++++++++++
 6 files changed, 109 insertions(+), 6 deletions(-)

diff --cc 
catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/operation/TestMysqlTableOperations.java
index db4fd2f0b4,456aeb89ee..b19db9406d
--- 
a/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/operation/TestMysqlTableOperations.java
+++ 
b/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/operation/TestMysqlTableOperations.java
@@@ -197,47 -197,39 +197,80 @@@ public class TestMysqlTableOperations e
          TABLE_OPERATIONS.drop(TEST_DB_NAME.toString(), newName), "table 
should be non-existent");
    }
  
+   @Test
+   public void testAlterTableUpdateColumnTypeKeepsDefaultValue() {
+     String tableName = RandomStringUtils.randomAlphabetic(16) + 
"_type_default_table";
+     JdbcColumn col_1 =
+         
JdbcColumn.builder().withName("col_1").withType(INT).withNullable(false).build();
+     JdbcColumn col_2 =
+         JdbcColumn.builder()
+             .withName("col_2")
+             .withType(Types.VarCharType.of(16))
+             .withDefaultValue(Literals.of("new", Types.VarCharType.of(16)))
+             .withNullable(false)
+             .build();
+     TABLE_OPERATIONS.create(
+         TEST_DB_NAME.toString(),
+         tableName,
+         new JdbcColumn[] {col_1, col_2},
+         "test_comment",
+         new HashMap<>(),
+         null,
+         Distributions.NONE,
+         new Index[0]);
+ 
+     TABLE_OPERATIONS.alterTable(
+         TEST_DB_NAME.toString(),
+         tableName,
+         TableChange.updateColumnType(new String[] {col_2.name()}, 
Types.VarCharType.of(32)));
+ 
+     JdbcTable load = TABLE_OPERATIONS.load(TEST_DB_NAME.toString(), 
tableName);
+     Column updated = load.columns()[1];
+     Assertions.assertEquals(Types.VarCharType.of(32), updated.dataType());
+     Assertions.assertEquals(Literals.of("new", Types.VarCharType.of(32)), 
updated.defaultValue());
+   }
+ 
 +  @Test
 +  public void testUpdateColumnPositionWithSpecialReferenceColumn() {
 +    String tableName = RandomStringUtils.randomAlphabetic(16) + 
"_position_table";
 +    JdbcColumn[] columns =
 +        new JdbcColumn[] {
 +          
JdbcColumn.builder().withName("id").withType(INT).withNullable(false).build(),
 +          JdbcColumn.builder().withName("status").withType(VARCHAR).build(),
 +          JdbcColumn.builder().withName("order-id").withType(VARCHAR).build(),
 +          JdbcColumn.builder().withName("key").withType(VARCHAR).build()
 +        };
 +    TABLE_OPERATIONS.create(
 +        TEST_DB_NAME.toString(),
 +        tableName,
 +        columns,
 +        "test_comment",
 +        new HashMap<>(),
 +        null,
 +        Distributions.NONE,
 +        new Index[0]);
 +
 +    TABLE_OPERATIONS.alterTable(
 +        TEST_DB_NAME.toString(),
 +        tableName,
 +        TableChange.updateColumnPosition(
 +            new String[] {"status"}, 
TableChange.ColumnPosition.after("order-id")));
 +    JdbcTable load = TABLE_OPERATIONS.load(TEST_DB_NAME.toString(), 
tableName);
 +    Assertions.assertArrayEquals(
 +        new String[] {"id", "order-id", "status", "key"},
 +        
Arrays.stream(load.columns()).map(Column::name).toArray(String[]::new));
 +
 +    // A null position moves the column after the last column `key`, a 
reserved word.
 +    TABLE_OPERATIONS.alterTable(
 +        TEST_DB_NAME.toString(),
 +        tableName,
 +        TableChange.updateColumnPosition(new String[] {"id"}, null));
 +    load = TABLE_OPERATIONS.load(TEST_DB_NAME.toString(), tableName);
 +    Assertions.assertArrayEquals(
 +        new String[] {"order-id", "status", "key", "id"},
 +        
Arrays.stream(load.columns()).map(Column::name).toArray(String[]::new));
 +  }
 +
    @Test
    public void testAlterTable() {
      String tableName = RandomStringUtils.randomAlphabetic(16) + "_al_table";
diff --cc 
catalogs/catalog-jdbc-starrocks/src/test/java/org/apache/gravitino/catalog/starrocks/operation/TestStarRocksTableOperations.java
index 6259c364c0,39763b3574..1af9acc2ff
--- 
a/catalogs/catalog-jdbc-starrocks/src/test/java/org/apache/gravitino/catalog/starrocks/operation/TestStarRocksTableOperations.java
+++ 
b/catalogs/catalog-jdbc-starrocks/src/test/java/org/apache/gravitino/catalog/starrocks/operation/TestStarRocksTableOperations.java
@@@ -251,45 -251,47 +251,85 @@@ public class TestStarRocksTableOperatio
        TABLE_OPERATIONS.drop(databaseName, tableName);
      }
    }
+ 
+   @Test
+   public void testAlterTableUpdateColumnTypeKeepsDefaultValue() {
+     String tableName = 
GravitinoITUtils.genRandomName("starrocks_type_default_test_table");
+     JdbcColumn col_1 = 
JdbcColumn.builder().withName("col_1").withType(INT).build();
+     // The wide col_2 keeps col_3 out of the default key columns, so col_3 is 
a value column.
+     JdbcColumn col_2 = 
JdbcColumn.builder().withName("col_2").withType(VARCHAR_255).build();
+     JdbcColumn col_3 =
+         JdbcColumn.builder()
+             .withName("col_3")
+             .withType(Types.VarCharType.of(16))
+             .withDefaultValue(Literals.of("new", Types.VarCharType.of(16)))
+             .build();
+     TABLE_OPERATIONS.create(
+         databaseName,
+         tableName,
+         new JdbcColumn[] {col_1, col_2, col_3},
+         "test_comment",
+         createProperties(),
+         null,
+         Distributions.hash(DEFAULT_BUCKET_SIZE, 
NamedReference.field("col_1")),
+         new Index[0]);
+ 
+     TABLE_OPERATIONS.alterTable(
+         databaseName,
+         tableName,
+         TableChange.updateColumnType(new String[] {col_3.name()}, 
Types.VarCharType.of(32)));
+ 
+     // StarRocks applies schema changes asynchronously.
+     Awaitility.await()
+         .atMost(MAX_WAIT_IN_SECONDS, TimeUnit.SECONDS)
+         .pollInterval(WAIT_INTERVAL_IN_SECONDS, TimeUnit.SECONDS)
+         .untilAsserted(
+             () -> {
+               Column updated = TABLE_OPERATIONS.load(databaseName, 
tableName).columns()[2];
+               Assertions.assertEquals(Types.VarCharType.of(32), 
updated.dataType());
+               Assertions.assertEquals(
+                   Literals.of("new", Types.VarCharType.of(32)), 
updated.defaultValue());
+             });
+   }
  
 +  @Test
 +  public void testUpdateColumnPositionAfterReservedWordColumn() {
 +    String tableName = 
GravitinoITUtils.genRandomName("starrocks_position_test_table");
 +    // The wide col_2 keeps status and key out of the default key columns.
 +    JdbcColumn[] columns =
 +        new JdbcColumn[] {
 +          JdbcColumn.builder().withName("col_1").withType(INT).build(),
 +          
JdbcColumn.builder().withName("col_2").withType(VARCHAR_255).build(),
 +          
JdbcColumn.builder().withName("status").withType(VARCHAR_255).build(),
 +          JdbcColumn.builder().withName("key").withType(VARCHAR_255).build()
 +        };
 +    TABLE_OPERATIONS.create(
 +        databaseName,
 +        tableName,
 +        columns,
 +        "test_comment",
 +        createProperties(),
 +        null,
 +        Distributions.hash(DEFAULT_BUCKET_SIZE, 
NamedReference.field("col_1")),
 +        new Index[0]);
 +
 +    // A null position moves the column after the last column `key`, a 
reserved word.
 +    TABLE_OPERATIONS.alterTable(
 +        databaseName, tableName, TableChange.updateColumnPosition(new 
String[] {"status"}, null));
 +
 +    // StarRocks applies schema changes asynchronously.
 +    Awaitility.await()
 +        .atMost(MAX_WAIT_IN_SECONDS, TimeUnit.SECONDS)
 +        .pollInterval(WAIT_INTERVAL_IN_SECONDS, TimeUnit.SECONDS)
 +        .untilAsserted(
 +            () ->
 +                Assertions.assertArrayEquals(
 +                    new String[] {"col_1", "col_2", "key", "status"},
 +                    Arrays.stream(TABLE_OPERATIONS.load(databaseName, 
tableName).columns())
 +                        .map(Column::name)
 +                        .toArray(String[]::new)));
 +  }
 +
    @Test
    public void testAlterTable() {
      String tableName = 
GravitinoITUtils.genRandomName("starrocks_alter_test_table");

Reply via email to