Skip to content

Commit

Permalink
[hive] Open the cascade to update (apache#2721)
Browse files Browse the repository at this point in the history
  • Loading branch information
MonsterChenzhuo authored Jan 25, 2024
1 parent 437d421 commit 288381d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ protected void alterTableImpl(Identifier identifier, List<SchemaChange> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 288381d

Please sign in to comment.