Skip to content

HIVE-27193: Database names starting with '@' cause error during ALTER…#6371

Open
ashniku wants to merge 1 commit intoapache:masterfrom
ashniku:HIVE-27193
Open

HIVE-27193: Database names starting with '@' cause error during ALTER…#6371
ashniku wants to merge 1 commit intoapache:masterfrom
ashniku:HIVE-27193

Conversation

@ashniku
Copy link

@ashniku ashniku commented Mar 16, 2026

…/DROP table

What changes were proposed in this pull request?
I have mofified "MetaStoreUtils.java", updated "hasCatalogName" to return true only if the database name both starts with the catalog marker (@) and contains the catalog-database separator (#).
-->

Why are the changes needed?
The issue is caused by MetaStoreUtils.hasCatalogName incorrectly identifying database names that start with the '@' character as catalog-prepended names. This leads to a failure in MetaStoreUtils.parseDbName when it tries to split the name using the '#' separator, which is missing in regular database names starting with '@'.

Proposed Changes
[Metastore Common]
[MODIFY] MetaStoreUtils.java
Update hasCatalogName
to return true only if the database name both starts with the catalog marker (@) and contains the catalog-database separator (#).

Does this PR introduce any user-facing change?
NO
-->

How was this patch tested?
CREATE DATABASE @test;
USE @test;
CREATE TABLE testtable (c1 INT);
ALTER TABLE testtable ADD COLUMNS (c2 INT);
DROP TABLE testtable;
DROP DATABASE @test;

Copy link
Author

@ashniku ashniku left a comment

Choose a reason for hiding this comment

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

can someone please review

@Neer393
Copy link
Contributor

Neer393 commented Mar 17, 2026

CI is failing. Can you please fix it first ?

@ashniku
Copy link
Author

ashniku commented Mar 18, 2026

closing the PR, I will re-open again

@ashniku ashniku closed this Mar 18, 2026
@ashniku
Copy link
Author

ashniku commented Mar 18, 2026

retest this please

@sonarqubecloud
Copy link

@@ -0,0 +1,6 @@
CREATE DATABASE `@test`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use meaningful test file names that can help understand the purpose of the qtest file in future

@@ -0,0 +1,44 @@
PREHOOK: query: CREATE DATABASE `@test`
Copy link
Contributor

Choose a reason for hiding this comment

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

Same for this

CREATE DATABASE `@test`;
USE `@test`;
CREATE TABLE testtable (c1 INT);
ALTER TABLE testtable ADD COLUMNS (c2 INT);
Copy link
Contributor

@Neer393 Neer393 Mar 18, 2026

Choose a reason for hiding this comment

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

Instead of using the database and alter and drop table, can you run the query as mentioned in the JIRA as I see that the issue is seen when hive tries to parse dbName.tableName where the dbName has the special character @ as it looks out for the catalog name.

Change queries to

ALTER TABLE `@test`.testtable ADD COLUMNS (c2 INT);
DROP TABLE `@test`.testtable;

You should also create another table named testtable2 and try the following queries as well

ALTER TABLE `@hive#@test`.testtable ADD COLUMNS (c2 INT);
DROP TABLE `@hive#@test`.testtable;

Copy link
Author

Choose a reason for hiding this comment

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

@Neer393 The Jira was created
ALTER TABLE @test.testtable ADD COLUMNS (c2 INT);
DROP TABLE @test.testtable;
This above one succeeds.

I just have a doubt on below:

ALTER TABLE @hive#test.testtable ADD COLUMNS (c2 INT);
DROP TABLE @hive#test.testtable;In this case @hive#test  the whole word is database or it is deciphered as catalog#database. The purpose is to check with @  as per the kita.

Could you please let me know??

Copy link
Author

Choose a reason for hiding this comment

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

Can you please confirm if below needs to be executed:

create database@hive#test; create table @hive#test.testtable (c1 INT); ALTER TABLE @hive#test.testtable ADD COLUMNS (c2 INT); DROP TABLE @hive#test.testtable;

In that case this works? Can you please confirm, so that I can put in qtest

Copy link
Contributor

Choose a reason for hiding this comment

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

In this case @hive#test  the whole word is database or it is deciphered as catalog#database. The purpose is to check with @  as per the kita.

It is deciphered as @catalog#database
So as per this JIRA, ALTER TABLE queries are failing because they call the MetastoreUtils.parseDbName() method which is calling the MetastoreUtils.hasCatalogName() method which you have fixed but the purpose of parseDbName is that it should return an array of size 2 where the 1st element is catalog name and the 2nd element is the database name.

So just to make sure both with and without catalog name works, I have asked you to run both queries

Copy link
Contributor

Choose a reason for hiding this comment

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

CREATE DATABASE `@test`;
CREATE TABLE `@test`.testtable (c1 INT);
ALTER TABLE `@hive#@test`.testtable ADD COLUMNS (c2 INT);
DROP TABLE `@hive#@test`.testtable;
DROP DATABASE `@test`;

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants