This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-paimon.git
The following commit(s) were added to refs/heads/master by this push:
new 572c16b34 [hive] fix alter paimon table options cannot be synchronized
to hive parameters. (#2810)
572c16b34 is described below
commit 572c16b34defffebcf96b385c12b0a86fab6316d
Author: herefree <[email protected]>
AuthorDate: Mon Jan 29 19:29:32 2024 +0800
[hive] fix alter paimon table options cannot be synchronized to hive
parameters. (#2810)
---
.../java/org/apache/paimon/hive/HiveCatalog.java | 5 +++
.../org/apache/paimon/hive/HiveCatalogTest.java | 52 ++++++++++++++++++++++
2 files changed, 57 insertions(+)
diff --git
a/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveCatalog.java
b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveCatalog.java
index 69109e552..7d50b7e8b 100644
---
a/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveCatalog.java
+++
b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveCatalog.java
@@ -438,6 +438,7 @@ public class HiveCatalog extends AbstractCatalog {
try {
// sync to hive hms
Table table = client.getTable(identifier.getDatabaseName(),
identifier.getObjectName());
+ updateHmsTablePars(table, schema);
updateHmsTable(table, identifier, schema);
client.alter_table(
identifier.getDatabaseName(), identifier.getObjectName(),
table, true);
@@ -565,6 +566,10 @@ public class HiveCatalog extends AbstractCatalog {
locationHelper.specifyTableLocation(table,
getDataTableLocation(identifier).toString());
}
+ private void updateHmsTablePars(Table table, TableSchema schema) {
+
table.getParameters().putAll(convertToPropertiesPrefixKey(schema.options(),
HIVE_PREFIX));
+ }
+
@VisibleForTesting
public IMetaStoreClient getHmsClient() {
return client;
diff --git
a/paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/HiveCatalogTest.java
b/paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/HiveCatalogTest.java
index ac80a276a..f88969de7 100644
---
a/paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/HiveCatalogTest.java
+++
b/paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/HiveCatalogTest.java
@@ -22,6 +22,7 @@ import org.apache.paimon.catalog.CatalogTestBase;
import org.apache.paimon.catalog.Identifier;
import org.apache.paimon.options.Options;
import org.apache.paimon.schema.Schema;
+import org.apache.paimon.schema.SchemaChange;
import org.apache.paimon.types.DataField;
import org.apache.paimon.types.DataTypes;
import org.apache.paimon.utils.CommonTestUtils;
@@ -39,6 +40,7 @@ import org.mockito.MockedStatic;
import org.mockito.Mockito;
import java.lang.reflect.Field;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -218,4 +220,54 @@ public class HiveCatalogTest extends CatalogTestBase {
fail("Test failed due to exception: " + e.getMessage());
}
}
+
+ @Test
+ public void testAlterHiveTableParameters() {
+ try {
+ // Create a new database for the test
+ String databaseName = "test_db";
+ catalog.createDatabase(databaseName, false);
+
+ // Create a new table with Hive table parameters
+ String tableName = "new_table";
+ Map<String, String> options = new HashMap<>();
+ options.put("hive.table.owner", "Jon");
+ options.put("hive.storage.format", "ORC");
+
+ Schema addHiveTableParametersSchema =
+ new Schema(
+ Lists.newArrayList(
+ new DataField(0, "pk", DataTypes.INT()),
+ new DataField(1, "col1",
DataTypes.STRING()),
+ new DataField(2, "col2",
DataTypes.STRING())),
+ Collections.emptyList(),
+ Collections.emptyList(),
+ options,
+ "");
+
+ catalog.createTable(
+ Identifier.create(databaseName, tableName),
+ addHiveTableParametersSchema,
+ false);
+
+ SchemaChange schemaChange1 =
SchemaChange.setOption("hive.table.owner", "Hms");
+ SchemaChange schemaChange2 =
+ SchemaChange.setOption("hive.table.create_time",
"2024-01-22");
+ catalog.alterTable(
+ Identifier.create(databaseName, tableName),
+ Arrays.asList(schemaChange1, schemaChange2),
+ false);
+
+ Field clientField = HiveCatalog.class.getDeclaredField("client");
+ clientField.setAccessible(true);
+ IMetaStoreClient client = (IMetaStoreClient)
clientField.get(catalog);
+ Table table = client.getTable(databaseName, tableName);
+ Map<String, String> tableProperties = table.getParameters();
+
+ assertThat(tableProperties).containsEntry("table.owner", "Hms");
+ assertThat(tableProperties).containsEntry("table.create_time",
"2024-01-22");
+ } catch (Exception e) {
+ fail("Test failed due to exception: " + e.getMessage());
+ }
+ }
}