marton-bod commented on a change in pull request #2129:
URL: https://github.com/apache/iceberg/pull/2129#discussion_r562013604



##########
File path: mr/src/main/java/org/apache/iceberg/mr/Catalogs.java
##########
@@ -180,47 +186,80 @@ public static boolean dropTable(Configuration conf, 
Properties props) {
   /**
    * Returns true if HiveCatalog is used
    * @param conf a Hadoop conf
+   * @param props the controlling properties
    * @return true if the Catalog is HiveCatalog
    */
-  public static boolean hiveCatalog(Configuration conf) {
-    return HIVE.equalsIgnoreCase(conf.get(InputFormatConfig.CATALOG));
+  public static boolean hiveCatalog(Configuration conf, Properties props) {
+    String catalogName = props.getProperty(InputFormatConfig.TABLE_CATALOG);
+    if (catalogName != null) {
+      return 
HIVE.equals(conf.get(String.format(InputFormatConfig.CATALOG_TYPE_TEMPLATE, 
catalogName)));

Review comment:
       Do we want to use `equalsIgnoreCase` here too? it seems that now 
insensitivity is allowed for the global config but not for the table-level 
config

##########
File path: mr/src/main/java/org/apache/iceberg/mr/Catalogs.java
##########
@@ -180,47 +186,80 @@ public static boolean dropTable(Configuration conf, 
Properties props) {
   /**
    * Returns true if HiveCatalog is used
    * @param conf a Hadoop conf
+   * @param props the controlling properties
    * @return true if the Catalog is HiveCatalog
    */
-  public static boolean hiveCatalog(Configuration conf) {
-    return HIVE.equalsIgnoreCase(conf.get(InputFormatConfig.CATALOG));
+  public static boolean hiveCatalog(Configuration conf, Properties props) {
+    String catalogName = props.getProperty(InputFormatConfig.TABLE_CATALOG);
+    if (catalogName != null) {
+      return 
HIVE.equals(conf.get(String.format(InputFormatConfig.CATALOG_TYPE_TEMPLATE, 
catalogName)));
+    } else {
+      if 
(HIVE.equals(conf.get(String.format(InputFormatConfig.CATALOG_TYPE_TEMPLATE, 
"default")))) {
+        return true;
+      } else {
+        return HIVE.equalsIgnoreCase(conf.get(InputFormatConfig.CATALOG));
+      }
+    }
   }
 
   @VisibleForTesting
-  static Optional<Catalog> loadCatalog(Configuration conf) {
-    String catalogLoaderClass = 
conf.get(InputFormatConfig.CATALOG_LOADER_CLASS);
-
-    if (catalogLoaderClass != null) {
-      CatalogLoader loader = (CatalogLoader) 
DynConstructors.builder(CatalogLoader.class)
-              .impl(catalogLoaderClass)
-              .build()
-              .newInstance();
-      Catalog catalog = loader.load(conf);
-      LOG.info("Loaded catalog {} using {}", catalog, catalogLoaderClass);
-      return Optional.of(catalog);
+  static Optional<Catalog> loadCatalog(Configuration conf, String catalogName) 
{
+    String catalogType;
+    String name = catalogName;
+    if (name == null) {
+      name = "default";
     }
+    catalogType = 
conf.get(String.format(InputFormatConfig.CATALOG_TYPE_TEMPLATE, name));
 
-    String catalogName = conf.get(InputFormatConfig.CATALOG);
+    // keep both catalog configuration methods for seamless transition
+    if (catalogType != null) {
+    // new logic
+      return loadCatalog(conf, catalogType, 
String.format(InputFormatConfig.CATALOG_WAREHOUSE_TEMPLATE, name),
+              String.format(InputFormatConfig.CATALOG_LOADER_CLASS_TEMPLATE, 
name));
+    } else {
+      // old logic
+      // use catalog {@link InputFormatConfig.CATALOG} stored in global hive 
config if table specific catalog
+      // configuration or default catalog definition is missing

Review comment:
       Do we want to add a debug log here to see which catalog we are loading 
and whether based on global or table-level conf? might help with debugging 
customer cases

##########
File path: mr/src/main/java/org/apache/iceberg/mr/Catalogs.java
##########
@@ -180,47 +186,80 @@ public static boolean dropTable(Configuration conf, 
Properties props) {
   /**
    * Returns true if HiveCatalog is used
    * @param conf a Hadoop conf
+   * @param props the controlling properties
    * @return true if the Catalog is HiveCatalog
    */
-  public static boolean hiveCatalog(Configuration conf) {
-    return HIVE.equalsIgnoreCase(conf.get(InputFormatConfig.CATALOG));
+  public static boolean hiveCatalog(Configuration conf, Properties props) {
+    String catalogName = props.getProperty(InputFormatConfig.TABLE_CATALOG);
+    if (catalogName != null) {
+      return 
HIVE.equals(conf.get(String.format(InputFormatConfig.CATALOG_TYPE_TEMPLATE, 
catalogName)));
+    } else {
+      if 
(HIVE.equals(conf.get(String.format(InputFormatConfig.CATALOG_TYPE_TEMPLATE, 
"default")))) {
+        return true;
+      } else {
+        return HIVE.equalsIgnoreCase(conf.get(InputFormatConfig.CATALOG));
+      }
+    }
   }
 
   @VisibleForTesting
-  static Optional<Catalog> loadCatalog(Configuration conf) {
-    String catalogLoaderClass = 
conf.get(InputFormatConfig.CATALOG_LOADER_CLASS);
-
-    if (catalogLoaderClass != null) {
-      CatalogLoader loader = (CatalogLoader) 
DynConstructors.builder(CatalogLoader.class)
-              .impl(catalogLoaderClass)
-              .build()
-              .newInstance();
-      Catalog catalog = loader.load(conf);
-      LOG.info("Loaded catalog {} using {}", catalog, catalogLoaderClass);
-      return Optional.of(catalog);
+  static Optional<Catalog> loadCatalog(Configuration conf, String catalogName) 
{
+    String catalogType;
+    String name = catalogName;
+    if (name == null) {
+      name = "default";
     }
+    catalogType = 
conf.get(String.format(InputFormatConfig.CATALOG_TYPE_TEMPLATE, name));
 
-    String catalogName = conf.get(InputFormatConfig.CATALOG);
+    // keep both catalog configuration methods for seamless transition
+    if (catalogType != null) {
+    // new logic
+      return loadCatalog(conf, catalogType, 
String.format(InputFormatConfig.CATALOG_WAREHOUSE_TEMPLATE, name),
+              String.format(InputFormatConfig.CATALOG_LOADER_CLASS_TEMPLATE, 
name));
+    } else {
+      // old logic
+      // use catalog {@link InputFormatConfig.CATALOG} stored in global hive 
config if table specific catalog
+      // configuration or default catalog definition is missing

Review comment:
       Do we want to add a debug log here to see which catalog we are loading 
and whether based on global or table-level conf? might help with debugging 
issues

##########
File path: 
mr/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergStorageHandlerWithMultipleCatalogs.java
##########
@@ -0,0 +1,143 @@
+/*
+ * 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.iceberg.mr.hive;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import org.apache.iceberg.FileFormat;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.data.Record;
+import org.apache.iceberg.mr.InputFormatConfig;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class TestHiveIcebergStorageHandlerWithMultipleCatalogs {
+
+  private static final String[] EXECUTION_ENGINES = new String[] { "tez", "mr" 
};
+  private static final String HIVECATALOGNAME = "table1_catalog";
+  private static final String OTHERCATALOGNAME = "table2_catalog";
+  private static TestHiveShell shell;
+
+  @Parameterized.Parameter(0)
+  public FileFormat fileFormat1;
+  @Parameterized.Parameter(1)
+  public FileFormat fileFormat2;
+  @Parameterized.Parameter(2)
+  public String executionEngine;
+  @Parameterized.Parameter(3)
+  public TestTables.TestTableType testTableType1;
+  @Parameterized.Parameter(4)
+  public String table1CatalogName;
+  @Parameterized.Parameter(5)
+  public TestTables.TestTableType testTableType2;
+  @Parameterized.Parameter(6)
+  public String table2CatalogName;
+
+  @Rule
+  public TemporaryFolder temp = new TemporaryFolder();
+  private TestTables testTables1;
+  private TestTables testTables2;
+
+  @Parameterized.Parameters(name = "fileFormat={0}, fileFormat={1}, 
engine={2}, tableType1={3}, catalogName1={4}, " +

Review comment:
       I guess it should be `fileFormat1` and `fileFormat2`?




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

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