You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/06/04 17:50:27 UTC

[GitHub] [iceberg] sumeetgajjar commented on a diff in pull request #4942: [Spark][Test]: Check before creating default namespace to avoid noisy AlreadyExistsExceptions in test logs

sumeetgajjar commented on code in PR #4942:
URL: https://github.com/apache/iceberg/pull/4942#discussion_r889599094


##########
spark/v3.2/spark/src/test/java/org/apache/iceberg/spark/SparkTestBaseWithCatalog.java:
##########
@@ -80,13 +80,24 @@ public SparkTestBaseWithCatalog(String catalogName, String implementation, Map<S
     spark.conf().set("spark.sql.catalog." + catalogName, implementation);
     config.forEach((key, value) -> spark.conf().set("spark.sql.catalog." + catalogName + "." + key, value));
 
-    if (config.get("type").equalsIgnoreCase("hadoop")) {
+    boolean isHadoopCatalog = config.get("type").equalsIgnoreCase("hadoop");
+    if (isHadoopCatalog) {
       spark.conf().set("spark.sql.catalog." + catalogName + ".warehouse", "file:" + warehouse);
     }
 
     this.tableName = (catalogName.equals("spark_catalog") ? "" : catalogName + ".") + "default.table";
 
-    sql("CREATE NAMESPACE IF NOT EXISTS default");
+    // When Hive API is invoked to create Namespace/Database using CREATE IF NOT EXISTS, the standalone HMS logs an
+    // AlreadyExistsException exception in the test logs thereby generating unwanted error logs. Thus checking if a
+    // namespace exists before creating one to keep the test logs noise-free.
+    // HMS is not involved in case HadoopCatalog, thus skipping the check for HadoopCatalog.
+    if (isHadoopCatalog) {
+      sql("CREATE NAMESPACE IF NOT EXISTS default");
+    } else {
+      if (!validationNamespaceCatalog.namespaceExists(Namespace.of("default"))) {

Review Comment:
   Hi @pvary - simplified the namespace creation logic further.
    
   However, that failed `TestNamespaceSQL#testListNamespace` test so had to fix it. The fix actually simplifies the assertion logic in `TestNamespaceSQL#testListNamespace` and removes a conditional as well :)



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