ebyhr commented on code in PR #14295:
URL: https://github.com/apache/iceberg/pull/14295#discussion_r2424913522
##########
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveCatalog.java:
##########
@@ -1208,4 +1209,39 @@ public void
testDatabaseLocationWithSlashInWarehouseDir() {
assertThat(database.getLocationUri()).isEqualTo("s3://bucket/database.db");
}
+
+ @Test
+ public void testTableLocationWithTrailingSlashInDatabaseLocation() throws
TException {
+ Schema schema = getTestSchema();
+ TableIdentifier tableIdent = TableIdentifier.of(DB_NAME, "test_table");
+
+ // Create database with trailing slash in location
+ String dbName = "db_with_trailing_slash";
+ String dbLocationWithSlash = temp.resolve(dbName) + "/";
+ Database db = new Database(dbName, "Description", dbLocationWithSlash,
Maps.newHashMap());
+ HIVE_METASTORE_EXTENSION.metastoreClient().createDatabase(db);
+
+ try {
+ TableIdentifier tableInDbWithSlash = TableIdentifier.of(dbName,
tableIdent.name());
+ Table table = catalog.createTable(tableInDbWithSlash, schema);
+
+ // Verify table location doesn't have double slashes
+ assertThat(table.location())
+ .as("Table location should not contain multiple slashes")
+ .doesNotContain("//test_table")
+ .endsWith("/test_table");
+
+ // Verify the path is normalized correctly
+ String expectedLocation = temp.resolve(dbName) + "/test_table";
+ assertThat(URI.create(table.location()).getPath())
+ .as("Table location should be properly normalized")
+ .isEqualTo(expectedLocation);
+
+ // Dropping the test table
+ catalog.dropTable(tableInDbWithSlash);
+ } finally {
+ // Dropping the test database
+ HIVE_METASTORE_EXTENSION.metastoreClient().dropDatabase(dbName);
Review Comment:
nit: This line can show "Database xxx is not empty" message instead of the
failed reason if the above assertion at L126 fails for some reason. We could
enable `cascade` parameter for `dropDatabase` method.
##########
hive-metastore/src/test/java/org/apache/iceberg/hive/TestHiveCatalog.java:
##########
@@ -1208,4 +1209,39 @@ public void
testDatabaseLocationWithSlashInWarehouseDir() {
assertThat(database.getLocationUri()).isEqualTo("s3://bucket/database.db");
}
+
+ @Test
+ public void testTableLocationWithTrailingSlashInDatabaseLocation() throws
TException {
+ Schema schema = getTestSchema();
+ TableIdentifier tableIdent = TableIdentifier.of(DB_NAME, "test_table");
+
+ // Create database with trailing slash in location
+ String dbName = "db_with_trailing_slash";
+ String dbLocationWithSlash = temp.resolve(dbName) + "/";
+ Database db = new Database(dbName, "Description", dbLocationWithSlash,
Maps.newHashMap());
+ HIVE_METASTORE_EXTENSION.metastoreClient().createDatabase(db);
+
+ try {
+ TableIdentifier tableInDbWithSlash = TableIdentifier.of(dbName,
tableIdent.name());
+ Table table = catalog.createTable(tableInDbWithSlash, schema);
+
+ // Verify table location doesn't have double slashes
+ assertThat(table.location())
+ .as("Table location should not contain multiple slashes")
+ .doesNotContain("//test_table")
Review Comment:
nit: We could use `doesNotEndWith` method instead.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]