nastra commented on a change in pull request #3162:
URL: https://github.com/apache/iceberg/pull/3162#discussion_r712947128



##########
File path: mr/src/test/java/org/apache/iceberg/mr/TestCatalogs.java
##########
@@ -256,6 +256,20 @@ public void testLoadCatalogHive() {
     Assertions.assertThat(hiveCatalog.get()).isInstanceOf(HiveCatalog.class);
   }
 
+  @Test
+  public void testLoadCustomCatalogWithHiveCatalogTypeSet() {
+    String catalogName = "barCatalog";
+    conf.set(InputFormatConfig.catalogPropertyConfigKey(catalogName, 
CatalogUtil.ICEBERG_CATALOG_TYPE),
+            CatalogUtil.ICEBERG_CATALOG_TYPE_HIVE);
+    conf.set(InputFormatConfig.catalogPropertyConfigKey(catalogName, 
CatalogProperties.CATALOG_IMPL),
+            CustomHadoopCatalog.class.getName());
+    conf.set(InputFormatConfig.catalogPropertyConfigKey(catalogName, 
CatalogProperties.WAREHOUSE_LOCATION),
+            "/tmp/mylocation");
+    Optional<Catalog> hiveCatalog = Catalogs.loadCatalog(conf, catalogName);
+    
Assertions.assertThat(hiveCatalog.get()).isInstanceOf(CustomHadoopCatalog.class);

Review comment:
       should be 
`Assertions.assertThat(hiveCatalog).isPresent().get().isInstanceOf(CustomHadoopCatalog.class);`

##########
File path: mr/src/test/java/org/apache/iceberg/mr/TestCatalogs.java
##########
@@ -256,6 +256,20 @@ public void testLoadCatalogHive() {
     Assertions.assertThat(hiveCatalog.get()).isInstanceOf(HiveCatalog.class);
   }
 
+  @Test
+  public void testLoadCustomCatalogWithHiveCatalogTypeSet() {
+    String catalogName = "barCatalog";
+    conf.set(InputFormatConfig.catalogPropertyConfigKey(catalogName, 
CatalogUtil.ICEBERG_CATALOG_TYPE),
+            CatalogUtil.ICEBERG_CATALOG_TYPE_HIVE);
+    conf.set(InputFormatConfig.catalogPropertyConfigKey(catalogName, 
CatalogProperties.CATALOG_IMPL),
+            CustomHadoopCatalog.class.getName());
+    conf.set(InputFormatConfig.catalogPropertyConfigKey(catalogName, 
CatalogProperties.WAREHOUSE_LOCATION),
+            "/tmp/mylocation");
+    Optional<Catalog> hiveCatalog = Catalogs.loadCatalog(conf, catalogName);
+    
Assertions.assertThat(hiveCatalog.get()).isInstanceOf(CustomHadoopCatalog.class);
+    Assert.assertFalse("Catalog type shouldn't be Hive", 
Catalogs.hiveCatalog(conf, catalogName));

Review comment:
       personally I would prefer something like 
`Assertions.assertThat(Catalogs.getCatalogType(conf, 
catalogName)).isNotEqualTo(CatalogUtil.ICEBERG_CATALOG_TYPE_HIVE)` because it 
would tell you what the actual catalog type is when it fails, but that would 
require making `Catalogs.getCatalogType(..)` package-private

##########
File path: mr/src/main/java/org/apache/iceberg/mr/Catalogs.java
##########
@@ -269,23 +280,57 @@ public static boolean hiveCatalog(Configuration conf, 
Properties props) {
    * @return type of the catalog, can be null
    */
   private static String getCatalogType(Configuration conf, String catalogName) 
{
+    if (isCustomCatalogSet(conf, catalogName)) {
+      return null;
+    }
     if (catalogName != null) {
-      String catalogType = conf.get(InputFormatConfig.catalogPropertyConfigKey(
-          catalogName, CatalogUtil.ICEBERG_CATALOG_TYPE));
-      if (catalogName.equals(ICEBERG_HADOOP_TABLE_NAME)) {
-        return NO_CATALOG_TYPE;
-      } else {
-        return catalogType;
-      }
+      return getCatalogTypeFromCatalogName(conf, catalogName);
     } else {
-      String catalogType = conf.get(InputFormatConfig.CATALOG);
-      if (catalogType == null) {
-        return CatalogUtil.ICEBERG_CATALOG_TYPE_HIVE;
-      } else if (catalogType.equals(LOCATION)) {
-        return NO_CATALOG_TYPE;
-      } else {
-        return catalogType;
-      }
+      return getLegacyCatalogType(conf);
+    }
+  }
+
+  /**
+   * Returns true if {@link CatalogProperties#CATALOG_IMPL} is set.
+   * @param conf global hive configuration
+   * @param catalogName name of the catalog
+   * @return true if {@link CatalogProperties#CATALOG_IMPL} is set
+   */
+  private static boolean isCustomCatalogSet(Configuration conf, String 
catalogName) {
+    String catalogCustomImpl = 
conf.get(InputFormatConfig.catalogPropertyConfigKey(
+            catalogName, CatalogProperties.CATALOG_IMPL));
+    return catalogCustomImpl != null;

Review comment:
       nit: could be inlined and directly returned




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