rdblue commented on a change in pull request #3126:
URL: https://github.com/apache/iceberg/pull/3126#discussion_r712452351



##########
File path: 
spark3/src/main/java/org/apache/iceberg/spark/SparkSessionCatalog.java
##########
@@ -240,8 +245,38 @@ public void renameTable(Identifier from, Identifier to) 
throws NoSuchTableExcept
     }
   }
 
+  public boolean isHiveCatalogConfigValid(CaseInsensitiveStringMap options, 
StringBuilder errorMsg) {
+    String hadoopConfUri = 
SparkSession.active().sparkContext().conf().contains("spark.hadoop.hive.metastore.uris")
 ?
+            
SparkSession.active().sparkContext().conf().get("spark.hadoop.hive.metastore.uris")
 : null;
+    String catalogConfUri = options.get("uri");
+
+    if (hadoopConfUri == null) {
+      errorMsg.append("Hive uri config is missing");
+    } else if (catalogConfUri != null) {
+      LOG.warn("Don't set uri for SparkSessionCatalog" +
+              "set it only in hive conf");
+      if (!hadoopConfUri.equalsIgnoreCase(catalogConfUri)) {
+        errorMsg.append("Cannot set uri for SparkSessionCatalog: " +
+                "conflicts with Hive conf URI");
+      }
+    }
+
+    if (errorMsg.length() != 0) {
+      return false;
+    }
+
+    return true;
+  }
+
   @Override
   public final void initialize(String name, CaseInsensitiveStringMap options) {
+    if (options.containsKey("type") && 
options.get("type").equalsIgnoreCase("hive")) {
+      StringBuilder errorMsg = new StringBuilder();

Review comment:
       Using a string builder and detecting an error if it is non-empty is not 
a good way to implement this. That's brittle because there is no way to know 
that the string builder here must be empty before passing it into the check.
   
   In addition, using a string builder to create an error message will lead to 
long and hard to understand messages, and typos. We should avoid it.
   
   Instead, I recommend structuring the check as 
`checkHiveUri(options.get("uri"))` and throwing `IllegalArgumentException` from 
that method. There is no need to return a boolean or have a string builder 
side-effect.




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