You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "Rajeev-01 (via GitHub)" <gi...@apache.org> on 2025/10/11 07:45:44 UTC

[PR] Hive : Fixing the trailing slash issue for the database paths in HMS [iceberg]

Rajeev-01 opened a new pull request, #14295:
URL: https://github.com/apache/iceberg/pull/14295

   ### Summary
   
   - While we are creating a new table in hive, if location hasn't passed explicitly we are fetching database path from HMS and appending "/" followed by tableName.
   - There are no checks if the HMS db path has trailing slashes.
   - This commit fixes a bug where database locations with trailing slashes in Hive Metastore (HMS) would create table locations with double slashes (e.g. database_path//table_name).
   
   ### Test plan
   
   - Added an UT which will check end to end flow where we will create the db with path having trailing slash and they will be removed while creating the table using hiveCatalaog


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Hive : Fixing the trailing slash issue for the database paths in HMS [iceberg]

Posted by "kevinjqliu (via GitHub)" <gi...@apache.org>.
kevinjqliu commented on PR #14295:
URL: https://github.com/apache/iceberg/pull/14295#issuecomment-4270148911

   this has been backported to the 1.10.x (https://github.com/apache/iceberg/pull/16010) and will be included when we release 1.10.2 soon


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Hive : Fixing the trailing slash issue for the database paths in HMS [iceberg]

Posted by "Rajeev-01 (via GitHub)" <gi...@apache.org>.
Rajeev-01 commented on PR #14295:
URL: https://github.com/apache/iceberg/pull/14295#issuecomment-3393531645

   Thanks @singhpk234 for the approval. All checks are green, can you or someone please merge it as I didn't have the permission šŸ˜… 


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Hive : Fixing the trailing slash issue for the database paths in HMS [iceberg]

Posted by "kevinjqliu (via GitHub)" <gi...@apache.org>.
kevinjqliu commented on PR #14295:
URL: https://github.com/apache/iceberg/pull/14295#issuecomment-3403916735

   Thanks for the fix @Rajeev-01 and thanks everyone for the review. 


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Hive : Fixing the trailing slash issue for the database paths in HMS [iceberg]

Posted by "aalopatin (via GitHub)" <gi...@apache.org>.
aalopatin commented on PR #14295:
URL: https://github.com/apache/iceberg/pull/14295#issuecomment-4260812079

   @Rajeev-01 Hi šŸ‘‹ Does this MR solve this issue? https://github.com/apache/iceberg/issues/15908


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Hive : Fixing the trailing slash issue for the database paths in HMS [iceberg]

Posted by "huaxingao (via GitHub)" <gi...@apache.org>.
huaxingao commented on PR #14295:
URL: https://github.com/apache/iceberg/pull/14295#issuecomment-3395016786

   @Rajeev-01 Thanks for checking this out! Since this is a simple fix, I’m okay merging without a mocked test. I think we can keep the current test as a smoke check (or drop it if others prefer).


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Hive : Fixing the trailing slash issue for the database paths in HMS [iceberg]

Posted by "Rajeev-01 (via GitHub)" <gi...@apache.org>.
Rajeev-01 commented on PR #14295:
URL: https://github.com/apache/iceberg/pull/14295#issuecomment-4269202817

   > @Rajeev-01 Hi šŸ‘‹ Does this MR solve this issue? #15908
   
   Hey yeah @aalopatin it solves double slash issue for HMS catalog


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Hive : Fixing the trailing slash issue for the database paths in HMS [iceberg]

Posted by "Rajeev-01 (via GitHub)" <gi...@apache.org>.
Rajeev-01 commented on PR #14295:
URL: https://github.com/apache/iceberg/pull/14295#issuecomment-3393974021

   The only way to make it work is by mocking but it's better not to mock. 
   @huaxingao Can I keep the test as it is or remove it or modify it by mocking the dbPath?


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Hive : Fixing the trailing slash issue for the database paths in HMS [iceberg]

Posted by "huaxingao (via GitHub)" <gi...@apache.org>.
huaxingao commented on PR #14295:
URL: https://github.com/apache/iceberg/pull/14295#issuecomment-3393801516

   @Rajeev-01 Thanks for the PR. The fix looks good, but seems the test passes without the fix?


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Hive : Fixing the trailing slash issue for the database paths in HMS [iceberg]

Posted by "ebyhr (via GitHub)" <gi...@apache.org>.
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Hive : Fixing the trailing slash issue for the database paths in HMS [iceberg]

Posted by "Rajeev-01 (via GitHub)" <gi...@apache.org>.
Rajeev-01 commented on PR #14295:
URL: https://github.com/apache/iceberg/pull/14295#issuecomment-3393970515

   > @Rajeev-01 Thanks for the PR. The fix looks good, but seems the test passes without the fix?
   
   Hey yeah @huaxingao thanks for pointing it out, I should have tested it without the fix šŸ˜“. The reason for test is not working was the HMS createDatabase call is internally using the org.apache.hadoop.fs.Path for creating the path which normalizes the path by removing the trailing slashes. This will work with hadoop >= 3.x since the fix landed in this version https://issues.apache.org/jira/browse/HADOOP-16226. 


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Hive : Fixing the trailing slash issue for the database paths in HMS [iceberg]

Posted by "Rajeev-01 (via GitHub)" <gi...@apache.org>.
Rajeev-01 commented on PR #14295:
URL: https://github.com/apache/iceberg/pull/14295#issuecomment-3395075016

   cool thanks @huaxingao 
   @singhpk234 @pvary @kevinjqliu can you please ack if we are good to have it, if so we can merge it 
   


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org


Re: [PR] Hive : Fixing the trailing slash issue for the database paths in HMS [iceberg]

Posted by "kevinjqliu (via GitHub)" <gi...@apache.org>.
kevinjqliu merged PR #14295:
URL: https://github.com/apache/iceberg/pull/14295


-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org