diff --git a/common/src/main/java/com/datastrato/gravitino/dto/requests/TableCreateRequest.java b/common/src/main/java/com/datastrato/gravitino/dto/requests/TableCreateRequest.java index 4f8e538af7a..537bb5bfc3a 100644 --- a/common/src/main/java/com/datastrato/gravitino/dto/requests/TableCreateRequest.java +++ b/common/src/main/java/com/datastrato/gravitino/dto/requests/TableCreateRequest.java @@ -83,7 +83,7 @@ public TableCreateRequest( @Nullable Partitioning[] partitioning) { this.name = name; this.columns = columns; - this.comment = comment; + this.comment = comment == null ? "" : comment; this.properties = properties; this.sortOrders = sortOrders; this.distribution = distribution; @@ -92,6 +92,9 @@ public TableCreateRequest( @Override public void validate() throws IllegalArgumentException { + // should never happen + Preconditions.checkArgument(comment != null, "\"comment\" field should not be null"); + Preconditions.checkArgument( StringUtils.isNotBlank(name), "\"name\" field is required and cannot be empty"); Preconditions.checkArgument( diff --git a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/catalog/hive/CatalogHiveIT.java b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/catalog/hive/CatalogHiveIT.java index 5ef0ed81578..0ccc0858cc5 100644 --- a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/catalog/hive/CatalogHiveIT.java +++ b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/catalog/hive/CatalogHiveIT.java @@ -460,6 +460,18 @@ 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); + Assertions.assertEquals("", createdTable.comment()); + // test null partition resetSchema(); Table createdTable1 =