Skip to content

Hive : Fixing the trailing slash issue for the database paths in HMS - #14295

Merged
kevinjqliu merged 1 commit into
apache:mainfrom
Rajeev-01:fix-trailing-slash
Oct 14, 2025
Merged

kevinjqliu merged 1 commit into
apache:mainfrom
Rajeev-01:fix-trailing-slash

Conversation

@Rajeev-01

@Rajeev-01 Rajeev-01 commented Oct 11, 2025 •

Copy link
Copy Markdown
Contributor

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).
  • Posted the issue here : Trailing slash issue in Hive Metastore database paths while creating table #14296

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

@github-actions github-actions Bot added the hive label Oct 11, 2025

@singhpk234 singhpk234 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks @Rajeev-01 !

@Rajeev-01

Rajeev-01 commented Oct 11, 2025 •

Copy link
Copy Markdown
Contributor Author

Thanks @singhpk234 for the approval. All checks are green, can you or someone please merge it

@kevinjqliu kevinjqliu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Another potential issue is when setting the "location" value:

} else if (key.equals("location")) {
database.setLocationUri(value);

I originally thought this was an issue, but its fine since databaseLocation takes care of the trailing slash:

// Otherwise, stick to the {WAREHOUSE_DIR}/{DB_NAME}.db/{TABLE_NAME} path
String databaseLocation = databaseLocation(tableIdentifier.namespace().levels()[0]);
return String.format("%s/%s", databaseLocation, tableIdentifier.name());

@huaxingao

Copy link
Copy Markdown
Contributor

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

@Rajeev-01

Copy link
Copy Markdown
Contributor Author

@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.

@Rajeev-01

Rajeev-01 commented Oct 12, 2025 •

Copy link
Copy Markdown
Contributor Author

The only way to make it work is by mocking but it's better not to introduce mock in e2e tests.
@huaxingao Can I keep the test as it is or remove it since no use of it or modify it by mocking the dbPath?

@huaxingao

Copy link
Copy Markdown
Contributor

@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).

@Rajeev-01

Copy link
Copy Markdown
Contributor Author

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

// Verify table location doesn't have double slashes
assertThat(table.location())
.as("Table location should not contain multiple slashes")
.doesNotContain("//test_table")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We could use doesNotEndWith method instead.

catalog.dropTable(tableInDbWithSlash);
} finally {
// Dropping the test database
HIVE_METASTORE_EXTENSION.metastoreClient().dropDatabase(dbName);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kevinjqliu
kevinjqliu merged commit 34096a7 into apache:main Oct 14, 2025
42 checks passed
@kevinjqliu

Copy link
Copy Markdown
Contributor

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

@aalopatin

Copy link
Copy Markdown

@Rajeev-01 Hi 👋 Does this MR solve this issue? #15908

@Rajeev-01

Rajeev-01 commented Apr 17, 2026 •

Copy link
Copy Markdown
Contributor Author

@Rajeev-01 Hi 👋 Does this MR solve this issue? #15908

Hey yeah @aalopatin it solves double slash issue for HMS catalog, I thought of this will go in next release 😅

amogh-jahagirdar pushed a commit that referenced this pull request Apr 17, 2026
…14295) (#16010)

Co-authored-by: Trivedhi <85494284+Rajeev-01@users.noreply.github.com>
@kevinjqliu

Copy link
Copy Markdown
Contributor

this has been backported to the 1.10.x (#16010) and will be included when we release 1.10.2 soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants