Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hive] Sync primary-key/partition-key/bucket-id when sync to hms #4038

Merged
merged 5 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,21 @@ private Table createHiveTable(Identifier identifier, TableSchema tableSchema) {
Map<String, String> tblProperties;
if (syncAllProperties()) {
tblProperties = new HashMap<>(tableSchema.options());

// add primary-key, partition-key, bucket-id to tblproperties
if (!tableSchema.primaryKeys().isEmpty()) {
tblProperties.put(
CoreOptions.PRIMARY_KEY.key(), String.join(",", tableSchema.primaryKeys()));
}
if (!tableSchema.partitionKeys().isEmpty()) {
tblProperties.put(
CoreOptions.PARTITION.key(), String.join(",", tableSchema.partitionKeys()));
}
if (!tableSchema.bucketKeys().isEmpty()) {
tblProperties.put(
CoreOptions.BUCKET_KEY.key(), String.join(",", tableSchema.bucketKeys()));
}
tblProperties.put(CoreOptions.BUCKET.key(), String.valueOf(tableSchema.numBuckets()));
} else {
tblProperties = convertToPropertiesPrefixKey(tableSchema.options(), HIVE_PREFIX);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,41 @@ public void testCreateCatalogWithSyncTblProperties() throws Exception {
.await();
tEnv.executeSql("USE CATALOG paimon_catalog_sync").await();
tEnv.executeSql("USE test_db").await();
tEnv.executeSql("CREATE TABLE t01 ( aa INT, bb STRING ) WITH ( 'file.format' = 'avro' )")
tEnv.executeSql(
"CREATE TABLE t01 ( aa INT, bb STRING, cc STRING, PRIMARY KEY (cc, aa) NOT ENFORCED) PARTITIONED BY (cc) WITH ('file.format' = 'avro', 'bucket' = '3')")
.await();
// assert contain properties
List<String> descFormattedT01 = hiveShell.executeQuery("DESC FORMATTED t01");
assertThat(
hiveShell
.executeQuery("DESC FORMATTED t01")
.contains("\tfile.format \tavro "))
.isTrue();

assertThat(
hiveShell
.executeQuery("DESC FORMATTED t01")
.contains("\tprimary-key \tcc,aa "))
.isTrue();

assertThat(
hiveShell
.executeQuery("DESC FORMATTED t01")
.contains("\tpartition \tcc "))
.isTrue();

assertThat(
hiveShell
.executeQuery("DESC FORMATTED t01")
.contains("\tbucket-key \taa "))
.isTrue();

assertThat(
hiveShell
.executeQuery("DESC FORMATTED t01")
.contains("\tbucket \t3 "))
.isTrue();

tEnv.executeSql("ALTER TABLE t01 SET ( 'file.format' = 'parquet' )").await();
assertThat(
hiveShell
Expand Down Expand Up @@ -416,16 +442,42 @@ public void testCreateCatalogWithSyncTblProperties() throws Exception {
.await();
tEnv.executeSql("USE CATALOG paimon_catalog_sync01").await();
tEnv.executeSql("USE test_db").await();
tEnv.executeSql("CREATE TABLE t02 ( aa INT, bb STRING ) WITH ( 'file.format' = 'avro' )")
tEnv.executeSql(
"CREATE TABLE t02 ( aa INT, bb STRING, cc STRING, PRIMARY KEY (cc, aa) NOT ENFORCED) PARTITIONED BY (cc) WITH ('file.format' = 'avro', 'bucket' = '3')")
.await();

// assert not contain properties
List<String> descFormattedT02 = hiveShell.executeQuery("DESC FORMATTED t02");
assertThat(
hiveShell
.executeQuery("DESC FORMATTED t02")
.contains("\tfile.format \tavro "))
.isFalse();

assertThat(
hiveShell
.executeQuery("DESC FORMATTED t02")
.contains("\tprimary-key \tcc,aa "))
.isFalse();

assertThat(
hiveShell
.executeQuery("DESC FORMATTED t02")
.contains("\tpartition \tcc "))
.isFalse();

assertThat(
hiveShell
.executeQuery("DESC FORMATTED t02")
.contains("\tbucket-key \taa "))
.isFalse();

assertThat(
hiveShell
.executeQuery("DESC FORMATTED t02")
.contains("\tbucket \t3 "))
.isFalse();

tEnv.executeSql("ALTER TABLE t02 SET ( 'file.format' = 'parquet' )").await();
assertThat(
hiveShell
Expand Down
Loading