Skip to content

Commit

Permalink
[apache#1544] fix(hive): fix null comment in hive table property (apa…
Browse files Browse the repository at this point in the history
…che#1553)

### What changes were proposed in this pull request?

set empty string as default value of comment when creating table

### Why are the changes needed?

Fix: apache#1544 

### Does this PR introduce _any_ user-facing change?
no

### How was this patch tested?

IT added
  • Loading branch information
mchades committed Jan 24, 2024
1 parent ba61278 commit e71d218
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public Table toHiveTable(HiveTablePropertiesMetadata tablePropertiesMetadata) {

private Map<String, String> buildTableParameters() {
Map<String, String> parameters = Maps.newHashMap(properties());
parameters.put(COMMENT, comment);
Optional.ofNullable(comment).ifPresent(c -> parameters.put(COMMENT, c));
String ignore =
EXTERNAL_TABLE.name().equalsIgnoreCase(properties().get(TABLE_TYPE))
? parameters.put(EXTERNAL, "TRUE")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,17 @@ public void testCreateHiveTable() throws TException, InterruptedException {
assertTableEquals(createdTable, hiveTab);
checkTableReadWrite(hiveTab);

// test null comment
resetSchema();
createdTable =
catalog
.asTableCatalog()
.createTable(nameIdentifier, columns, null, properties, Transforms.EMPTY_TRANSFORM);
org.apache.hadoop.hive.metastore.api.Table hiveTab2 =
hiveClientPool.run(client -> client.getTable(schemaName, tableName));
assertTableEquals(createdTable, hiveTab2);
checkTableReadWrite(hiveTab);

// test null partition
resetSchema();
Table createdTable1 =
Expand Down Expand Up @@ -662,7 +673,7 @@ private void assertTableEquals(
Assertions.assertEquals(schemaName.toLowerCase(), hiveTab.getDbName());
Assertions.assertEquals(tableName.toLowerCase(), hiveTab.getTableName());
Assertions.assertEquals("MANAGED_TABLE", hiveTab.getTableType());
Assertions.assertEquals(TABLE_COMMENT, hiveTab.getParameters().get("comment"));
Assertions.assertEquals(createdTable.comment(), hiveTab.getParameters().get("comment"));

Assertions.assertEquals(HIVE_COL_NAME1, actualColumns.get(0).getName());
Assertions.assertEquals("tinyint", actualColumns.get(0).getType());
Expand Down

0 comments on commit e71d218

Please sign in to comment.