zabetak commented on code in PR #6371:
URL: https://github.com/apache/hive/pull/6371#discussion_r2979719224


##########
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/utils/TestParseDbName.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.api.MetaException;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.util.Arrays;
+
+@Category(MetastoreUnitTest.class)
+public class TestParseDbName {
+
+  @Test
+  public void testParseDbNameEdgeCases() throws MetaException {
+    Configuration conf = MetastoreConf.newMetastoreConf();
+    MetastoreConf.setVar(conf, MetastoreConf.ConfVars.CATALOG_DEFAULT, "hive");
+
+    // Reviewer edge cases:
+    // @ - Desigates @ as database in default catalog
+    String[] result = MetaStoreUtils.parseDbName("@", conf);
+    Assert.assertArrayEquals(new String[]{"hive", "@"}, result);
+
+    // @! -> ["", ""]

Review Comment:
   Comments are redundant and can be dropped sinceinput and output are clearly 
visible in the test.



##########
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/utils/TestParseDbName.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.api.MetaException;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.util.Arrays;
+
+@Category(MetastoreUnitTest.class)
+public class TestParseDbName {
+
+  @Test
+  public void testParseDbNameEdgeCases() throws MetaException {
+    Configuration conf = MetastoreConf.newMetastoreConf();
+    MetastoreConf.setVar(conf, MetastoreConf.ConfVars.CATALOG_DEFAULT, "hive");
+
+    // Reviewer edge cases:
+    // @ - Desigates @ as database in default catalog
+    String[] result = MetaStoreUtils.parseDbName("@", conf);
+    Assert.assertArrayEquals(new String[]{"hive", "@"}, result);

Review Comment:
   You can add static imports to `parseDbName` and `assertArrayEquals` and turn 
all these into one liner:
   ```java
   assertArrayEquals(new String[] {"hive", "@"}, parseDbName("@", conf));
   ```



##########
ql/src/test/queries/clientpositive/database_special_character.q:
##########
@@ -0,0 +1,5 @@
+CREATE DATABASE `@firstdb`;
+CREATE TABLE `@firstdb`.testtable (c1 INT);
+ALTER TABLE `@firstdb`.testtable ADD COLUMNS (c2 INT);
+DROP TABLE `@firstdb`.testtable;
+DROP DATABASE `@firstdb`;

Review Comment:
   Since we added unit tests with more coverage we could possibly drop this 
qtest.



##########
standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/MetaStoreUtils.java:
##########
@@ -1105,7 +1106,11 @@ public static String[] parseDbName(String dbName, 
Configuration conf) throws Met
         return new String[] {dbName.substring(1, dbName.length() - 1), null};
       } else if (dbName.endsWith(DB_EMPTY_MARKER)) {
         // This means the DB name is empty

Review Comment:
   If we assume that a valid catalog name always has a `CATALOG_DB_SEPARATOR` 
then we could start by splitting the name and then handling the two special 
cases afterwards (empty vs null DB).
   
   One way or the other we are changing the behavior of this method so let's 
try to make it as meaningful as possible.
   



##########
standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/utils/MetaStoreUtils.java:
##########
@@ -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) || 
dbName.endsWith(DB_EMPTY_MARKER));

Review Comment:
   `prependCatalogToDbName` assumes that `DB_EMPTY_MARKER` appears always 
together with `CATALOG_DB_SEPARATOR` so in this method we could just check for 
the `CATALOG_DB_SEPARATOR`. In other words a valid catalog name exists only if 
it appears between `@....#`.
   
   



##########
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/utils/TestParseDbName.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.api.MetaException;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.util.Arrays;
+
+@Category(MetastoreUnitTest.class)
+public class TestParseDbName {
+
+  @Test
+  public void testParseDbNameEdgeCases() throws MetaException {
+    Configuration conf = MetastoreConf.newMetastoreConf();
+    MetastoreConf.setVar(conf, MetastoreConf.ConfVars.CATALOG_DEFAULT, "hive");
+
+    // Reviewer edge cases:
+    // @ - Desigates @ as database in default catalog
+    String[] result = MetaStoreUtils.parseDbName("@", conf);
+    Assert.assertArrayEquals(new String[]{"hive", "@"}, result);
+
+    // @! -> ["", ""]
+    result = MetaStoreUtils.parseDbName("@!", conf);
+    Assert.assertArrayEquals(new String[]{"", ""}, result);
+
+    // @# -> ["", null]
+    result = MetaStoreUtils.parseDbName("@#", conf);
+    Assert.assertArrayEquals(new String[]{"", null}, result);
+
+    // @#db1 -> ["", "db1"]
+    result = MetaStoreUtils.parseDbName("@#db1", conf);
+    Assert.assertArrayEquals(new String[]{"", "db1"}, result);
+
+    // @cat1 - Desigates @cat1 as database in default catalog
+    result = MetaStoreUtils.parseDbName("@cat1", conf);
+    Assert.assertArrayEquals(new String[]{"hive", "@cat1"}, result);
+
+    // @cat1# -> ["cat1", null]
+    result = MetaStoreUtils.parseDbName("@cat1#", conf);
+    Assert.assertArrayEquals(new String[]{"cat1", null}, result);
+
+    // @cat1#! -> ["cat1", ""]
+    result = MetaStoreUtils.parseDbName("@cat1#!", conf);
+    Assert.assertArrayEquals(new String[]{"cat1", ""}, result);
+
+    // @cat1#@db1 -> ["cat1", "@db1"]
+    result = MetaStoreUtils.parseDbName("@cat1#@db1", conf);
+    Assert.assertArrayEquals(new String[]{"cat1", "@db1"}, result);
+
+    // @cat1##db1 -> ["cat1", "#db1"]
+    result = MetaStoreUtils.parseDbName("@cat1##db1", conf);
+    Assert.assertArrayEquals(new String[]{"cat1", "#db1"}, result);
+
+    // @cat1#db1 -> ["cat1", "db1"]
+    result = MetaStoreUtils.parseDbName("@cat1#db1", conf);
+    Assert.assertArrayEquals(new String[]{"cat1", "db1"}, result);
+
+    // @cat1#db1! -> ["cat1#db1", ""]
+    result = MetaStoreUtils.parseDbName("@cat1#db1!", conf);
+    Assert.assertArrayEquals(new String[]{"cat1#db1", ""}, result);
+
+    // @cat1! -> ["cat1", ""]
+    result = MetaStoreUtils.parseDbName("@cat1!", conf);
+    Assert.assertArrayEquals(new String[]{"cat1", ""}, result);
+
+    // #db1 -> ["hive", "#db1"]
+    result = MetaStoreUtils.parseDbName("#db1", conf);
+    Assert.assertArrayEquals(new String[]{"hive", "#db1"}, result);
+
+    // #! -> ["hive", "#!"]
+    result = MetaStoreUtils.parseDbName("#!", conf);
+    Assert.assertArrayEquals(new String[]{"hive", "#!"}, result);
+
+    // # -> ["hive", "#"]
+    result = MetaStoreUtils.parseDbName("#", conf);
+    Assert.assertArrayEquals(new String[]{"hive", "#"}, result);
+  }
+
+  private void assertThrowsMetaException(String dbName, Configuration conf) {

Review Comment:
   Unused method, please remove it.



##########
standalone-metastore/metastore-server/pom.xml:
##########
@@ -430,21 +430,17 @@
       <version>${wiremock.jre8.standalone.version}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter-api</artifactId>
+      <version>${junit.jupiter.version}</version>
+      <scope>test</scope>
+    </dependency>

Review Comment:
   The new test is not using jupiter APIs so why are the changes in the pom.xml 
needed?



##########
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/utils/TestParseDbName.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.api.MetaException;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.util.Arrays;
+
+@Category(MetastoreUnitTest.class)
+public class TestParseDbName {
+
+  @Test
+  public void testParseDbNameEdgeCases() throws MetaException {
+    Configuration conf = MetastoreConf.newMetastoreConf();
+    MetastoreConf.setVar(conf, MetastoreConf.ConfVars.CATALOG_DEFAULT, "hive");
+
+    // Reviewer edge cases:
+    // @ - Desigates @ as database in default catalog
+    String[] result = MetaStoreUtils.parseDbName("@", conf);
+    Assert.assertArrayEquals(new String[]{"hive", "@"}, result);
+
+    // @! -> ["", ""]
+    result = MetaStoreUtils.parseDbName("@!", conf);
+    Assert.assertArrayEquals(new String[]{"", ""}, result);
+
+    // @# -> ["", null]
+    result = MetaStoreUtils.parseDbName("@#", conf);
+    Assert.assertArrayEquals(new String[]{"", null}, result);
+
+    // @#db1 -> ["", "db1"]
+    result = MetaStoreUtils.parseDbName("@#db1", conf);
+    Assert.assertArrayEquals(new String[]{"", "db1"}, result);
+
+    // @cat1 - Desigates @cat1 as database in default catalog
+    result = MetaStoreUtils.parseDbName("@cat1", conf);
+    Assert.assertArrayEquals(new String[]{"hive", "@cat1"}, result);
+
+    // @cat1# -> ["cat1", null]
+    result = MetaStoreUtils.parseDbName("@cat1#", conf);
+    Assert.assertArrayEquals(new String[]{"cat1", null}, result);
+
+    // @cat1#! -> ["cat1", ""]
+    result = MetaStoreUtils.parseDbName("@cat1#!", conf);
+    Assert.assertArrayEquals(new String[]{"cat1", ""}, result);
+
+    // @cat1#@db1 -> ["cat1", "@db1"]
+    result = MetaStoreUtils.parseDbName("@cat1#@db1", conf);
+    Assert.assertArrayEquals(new String[]{"cat1", "@db1"}, result);
+
+    // @cat1##db1 -> ["cat1", "#db1"]
+    result = MetaStoreUtils.parseDbName("@cat1##db1", conf);
+    Assert.assertArrayEquals(new String[]{"cat1", "#db1"}, result);
+
+    // @cat1#db1 -> ["cat1", "db1"]
+    result = MetaStoreUtils.parseDbName("@cat1#db1", conf);
+    Assert.assertArrayEquals(new String[]{"cat1", "db1"}, result);
+
+    // @cat1#db1! -> ["cat1#db1", ""]
+    result = MetaStoreUtils.parseDbName("@cat1#db1!", conf);
+    Assert.assertArrayEquals(new String[]{"cat1#db1", ""}, result);
+
+    // @cat1! -> ["cat1", ""]
+    result = MetaStoreUtils.parseDbName("@cat1!", conf);
+    Assert.assertArrayEquals(new String[]{"cat1", ""}, result);

Review Comment:
   Based on `prependCatalogToDbName` the `DB_EMPTY_MARKER` is not meant to be 
used without `CATALOG_DB_SEPARATOR` so a more anticipated result would be `new 
String[]{"hive", "@cat1!"}`



##########
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/utils/TestParseDbName.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.api.MetaException;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.util.Arrays;
+
+@Category(MetastoreUnitTest.class)
+public class TestParseDbName {

Review Comment:
   It will be easier to find the test if we rename this to 
`TestMetastoreUtilsParseDbName`.



##########
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/utils/TestParseDbName.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.api.MetaException;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.util.Arrays;
+
+@Category(MetastoreUnitTest.class)
+public class TestParseDbName {
+
+  @Test
+  public void testParseDbNameEdgeCases() throws MetaException {
+    Configuration conf = MetastoreConf.newMetastoreConf();
+    MetastoreConf.setVar(conf, MetastoreConf.ConfVars.CATALOG_DEFAULT, "hive");
+
+    // Reviewer edge cases:
+    // @ - Desigates @ as database in default catalog
+    String[] result = MetaStoreUtils.parseDbName("@", conf);
+    Assert.assertArrayEquals(new String[]{"hive", "@"}, result);
+
+    // @! -> ["", ""]
+    result = MetaStoreUtils.parseDbName("@!", conf);
+    Assert.assertArrayEquals(new String[]{"", ""}, result);
+
+    // @# -> ["", null]
+    result = MetaStoreUtils.parseDbName("@#", conf);
+    Assert.assertArrayEquals(new String[]{"", null}, result);
+
+    // @#db1 -> ["", "db1"]
+    result = MetaStoreUtils.parseDbName("@#db1", conf);
+    Assert.assertArrayEquals(new String[]{"", "db1"}, result);
+
+    // @cat1 - Desigates @cat1 as database in default catalog
+    result = MetaStoreUtils.parseDbName("@cat1", conf);
+    Assert.assertArrayEquals(new String[]{"hive", "@cat1"}, result);
+
+    // @cat1# -> ["cat1", null]
+    result = MetaStoreUtils.parseDbName("@cat1#", conf);
+    Assert.assertArrayEquals(new String[]{"cat1", null}, result);
+
+    // @cat1#! -> ["cat1", ""]
+    result = MetaStoreUtils.parseDbName("@cat1#!", conf);
+    Assert.assertArrayEquals(new String[]{"cat1", ""}, result);
+
+    // @cat1#@db1 -> ["cat1", "@db1"]
+    result = MetaStoreUtils.parseDbName("@cat1#@db1", conf);
+    Assert.assertArrayEquals(new String[]{"cat1", "@db1"}, result);
+
+    // @cat1##db1 -> ["cat1", "#db1"]
+    result = MetaStoreUtils.parseDbName("@cat1##db1", conf);
+    Assert.assertArrayEquals(new String[]{"cat1", "#db1"}, result);
+
+    // @cat1#db1 -> ["cat1", "db1"]
+    result = MetaStoreUtils.parseDbName("@cat1#db1", conf);
+    Assert.assertArrayEquals(new String[]{"cat1", "db1"}, result);
+
+    // @cat1#db1! -> ["cat1#db1", ""]
+    result = MetaStoreUtils.parseDbName("@cat1#db1!", conf);
+    Assert.assertArrayEquals(new String[]{"cat1#db1", ""}, result);

Review Comment:
   In this case, I would expect `new String[]{"cat1", "db1!"}`.



-- 
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]

Reply via email to