From 288381d7d893482b4a7cd8fe64e0a2961a78d543 Mon Sep 17 00:00:00 2001 From: monster <60029759+MonsterChenzhuo@users.noreply.github.com> Date: Thu, 25 Jan 2024 16:34:57 +0800 Subject: [PATCH] [hive] Open the cascade to update (#2721) --- .../org/apache/paimon/hive/HiveCatalog.java | 3 +- .../hive/AlterFailHiveMetaStoreClient.java | 3 +- .../hive/AlterFailHiveMetaStoreClient.java | 3 +- .../paimon/hive/HiveCatalogITCaseBase.java | 35 +++++++++++++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) 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 ecf624c7081c..69109e552279 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 @@ -439,7 +439,8 @@ protected void alterTableImpl(Identifier identifier, List changes) // sync to hive hms Table table = client.getTable(identifier.getDatabaseName(), identifier.getObjectName()); updateHmsTable(table, identifier, schema); - client.alter_table(identifier.getDatabaseName(), identifier.getObjectName(), table); + client.alter_table( + identifier.getDatabaseName(), identifier.getObjectName(), table, true); } catch (Exception te) { schemaManager.deleteSchema(schema.id()); throw new RuntimeException(te); diff --git a/paimon-hive/paimon-hive-connector-2.3/src/test/java/org/apache/paimon/hive/AlterFailHiveMetaStoreClient.java b/paimon-hive/paimon-hive-connector-2.3/src/test/java/org/apache/paimon/hive/AlterFailHiveMetaStoreClient.java index a347859934de..ebd4684edf1b 100644 --- a/paimon-hive/paimon-hive-connector-2.3/src/test/java/org/apache/paimon/hive/AlterFailHiveMetaStoreClient.java +++ b/paimon-hive/paimon-hive-connector-2.3/src/test/java/org/apache/paimon/hive/AlterFailHiveMetaStoreClient.java @@ -46,7 +46,8 @@ public AlterFailHiveMetaStoreClient( } @Override - public void alter_table(String defaultDatabaseName, String tblName, Table table) + public void alter_table( + String defaultDatabaseName, String tblName, Table table, boolean cascade) throws InvalidOperationException, MetaException, TException { throw new TException(); } diff --git a/paimon-hive/paimon-hive-connector-3.1/src/test/java/org/apache/paimon/hive/AlterFailHiveMetaStoreClient.java b/paimon-hive/paimon-hive-connector-3.1/src/test/java/org/apache/paimon/hive/AlterFailHiveMetaStoreClient.java index 6bdbb38eaea4..ae6a1bb85ac4 100644 --- a/paimon-hive/paimon-hive-connector-3.1/src/test/java/org/apache/paimon/hive/AlterFailHiveMetaStoreClient.java +++ b/paimon-hive/paimon-hive-connector-3.1/src/test/java/org/apache/paimon/hive/AlterFailHiveMetaStoreClient.java @@ -46,7 +46,8 @@ public AlterFailHiveMetaStoreClient( } @Override - public void alter_table(String defaultDatabaseName, String tblName, Table table) + public void alter_table( + String defaultDatabaseName, String tblName, Table table, boolean cascade) throws InvalidOperationException, MetaException, TException { throw new TException(); } diff --git a/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/HiveCatalogITCaseBase.java b/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/HiveCatalogITCaseBase.java index 8744998562ac..051a23979023 100644 --- a/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/HiveCatalogITCaseBase.java +++ b/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/HiveCatalogITCaseBase.java @@ -935,6 +935,41 @@ public void testAddPartitionsForTag() throws Exception { "4\t40\t2023-10-17"); } + @Test + public void testHistoryPartitionsCascadeToUpdate() throws Exception { + tEnv.executeSql( + String.join( + "\n", + "CREATE TABLE t (", + " k INT,", + " v BIGINT,", + " PRIMARY KEY (k) NOT ENFORCED", + ") WITH (", + " 'bucket' = '2',", + " 'metastore.tag-to-partition' = 'dt'", + ")")); + tEnv.executeSql("INSERT INTO t VALUES (1, 10), (2, 20)").await(); + tEnv.executeSql("CALL sys.create_tag('test_db.t', '2023-10-16', 1)"); + + assertThat(hiveShell.executeQuery("SHOW PARTITIONS t")) + .containsExactlyInAnyOrder("dt=2023-10-16"); + + assertThat(hiveShell.executeQuery("SELECT k, v FROM t WHERE dt='2023-10-16'")) + .containsExactlyInAnyOrder("1\t10", "2\t20"); + + assertThat(hiveShell.executeQuery("SELECT * FROM t WHERE dt='2023-10-16'")) + .containsExactlyInAnyOrder("1\t10\t2023-10-16", "2\t20\t2023-10-16"); + + tEnv.executeSql("INSERT INTO t VALUES (3, 30), (4, 40)").await(); + tEnv.executeSql("CALL sys.create_tag('test_db.t', '2023-10-17', 2)"); + + tEnv.executeSql("ALTER TABLE t ADD z INT"); + tEnv.executeSql("INSERT INTO t VALUES (3, 30, 5), (4, 40, 6)").await(); + + assertThat(hiveShell.executeQuery("SELECT * FROM t WHERE dt='2023-10-16'")) + .containsExactlyInAnyOrder("1\t10\tNULL\t2023-10-16", "2\t20\tNULL\t2023-10-16"); + } + @Test public void testAddPartitionsForTagPreview() throws Exception { tEnv.executeSql(