This is an automated email from the ASF dual-hosted git repository.
zabetak pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/master by this push:
new 8d63cafe8d0 HIVE-27193: Database names starting with @ cause error
during ALTER/DROP table (#6371)
8d63cafe8d0 is described below
commit 8d63cafe8d0434d2fad0e6dfcb7c24744cef8d43
Author: Asish Kumar Patra <[email protected]>
AuthorDate: Fri Apr 3 18:50:09 2026 +0530
HIVE-27193: Database names starting with @ cause error during ALTER/DROP
table (#6371)
---
.../hive/metastore/utils/MetaStoreUtils.java | 30 ++++++------
.../utils/TestMetastoreUtilsParseDbName.java | 53 ++++++++++++++++++++++
2 files changed, 66 insertions(+), 17 deletions(-)
diff --git
a/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/MetaStoreUtils.java
b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/MetaStoreUtils.java
index 5fdb6a49f80..473a11cfa93 100644
---
a/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/MetaStoreUtils.java
+++
b/standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/MetaStoreUtils.java
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -1027,7 +1027,8 @@ public static WMPoolSchedulingPolicy
parseSchedulingPolicy(String schedulingPoli
private static boolean hasCatalogName(String dbName) {
return dbName != null && dbName.length() > 0 &&
- dbName.charAt(0) == CATALOG_DB_THRIFT_NAME_MARKER;
+ dbName.charAt(0) == CATALOG_DB_THRIFT_NAME_MARKER &&
+ dbName.contains(CATALOG_DB_SEPARATOR);
}
/**
@@ -1092,25 +1093,20 @@ public static String prependCatalogToDbName(String
dbName, Configuration conf) {
* in the database name.
* @return an array of two elements, the first being the catalog name, the
second the database
* name.
- * @throws MetaException if the name is not either just a database name or a
catalog plus
- * database name with the proper delimiters.
*/
- public static String[] parseDbName(String dbName, Configuration conf) throws
MetaException {
+ public static String[] parseDbName(String dbName, Configuration conf) {
if (dbName == null) {
return Arrays.copyOf(nullCatalogAndDatabase,
nullCatalogAndDatabase.length);
}
if (hasCatalogName(dbName)) {
- if (dbName.endsWith(CATALOG_DB_SEPARATOR)) {
- // This means the DB name is null
- return new String[] {dbName.substring(1, dbName.length() - 1), null};
- } else if (dbName.endsWith(DB_EMPTY_MARKER)) {
- // This means the DB name is empty
- return new String[] {dbName.substring(1, dbName.length() -
DB_EMPTY_MARKER.length() - 1), ""};
- }
String[] names = dbName.substring(1).split(CATALOG_DB_SEPARATOR, 2);
- if (names.length != 2) {
- throw new MetaException(dbName + " is prepended with the catalog
marker but does not " +
- "appear to have a catalog name in it");
+ if (names.length == 1) {
+ return new String[] {names[0], null};
+ }
+ if (names[1].isEmpty()) {
+ names[1] = null;
+ } else if (names[1].equals(DB_EMPTY_MARKER)) {
+ names[1] = "";
}
return names;
} else {
diff --git
a/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/utils/TestMetastoreUtilsParseDbName.java
b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/utils/TestMetastoreUtilsParseDbName.java
new file mode 100644
index 00000000000..34d8bd2320f
--- /dev/null
+++
b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/utils/TestMetastoreUtilsParseDbName.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.metastore.utils;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import static
org.apache.hadoop.hive.metastore.utils.MetaStoreUtils.parseDbName;
+import static org.junit.Assert.assertArrayEquals;
+
+@Category(MetastoreUnitTest.class)
+public class TestMetastoreUtilsParseDbName {
+
+ @Test
+ public void testParseDbNameEdgeCases() {
+ Configuration conf = MetastoreConf.newMetastoreConf();
+ MetastoreConf.setVar(conf, MetastoreConf.ConfVars.CATALOG_DEFAULT, "hive");
+
+ assertArrayEquals(new String[]{"hive", "@"}, parseDbName("@", conf));
+ assertArrayEquals(new String[]{"hive", "@!"}, parseDbName("@!", conf));
+ assertArrayEquals(new String[]{"", null}, parseDbName("@#", conf));
+ assertArrayEquals(new String[]{"", "db1"}, parseDbName("@#db1", conf));
+ assertArrayEquals(new String[]{"hive", "@cat1"}, parseDbName("@cat1",
conf));
+ assertArrayEquals(new String[]{"cat1", null}, parseDbName("@cat1#", conf));
+ assertArrayEquals(new String[]{"cat1", ""}, parseDbName("@cat1#!", conf));
+ assertArrayEquals(new String[]{"cat1", "@db1"}, parseDbName("@cat1#@db1",
conf));
+ assertArrayEquals(new String[]{"cat1", "#db1"}, parseDbName("@cat1##db1",
conf));
+ assertArrayEquals(new String[]{"cat1", "db1"}, parseDbName("@cat1#db1",
conf));
+ assertArrayEquals(new String[]{"cat1", "db1!"}, parseDbName("@cat1#db1!",
conf));
+ assertArrayEquals(new String[]{"hive", "@cat1!"}, parseDbName("@cat1!",
conf));
+ assertArrayEquals(new String[]{"hive", "#db1"}, parseDbName("#db1", conf));
+ assertArrayEquals(new String[]{"hive", "#!"}, parseDbName("#!", conf));
+ assertArrayEquals(new String[]{"hive", "#"}, parseDbName("#", conf));
+ }
+}