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 2020/07/27 08:49:05 UTC

[GitHub] [iceberg] massdosage commented on a change in pull request #1243: Add support for custom catalog to Iceberg StorageHandler (#1155)

massdosage commented on a change in pull request #1243:
URL: https://github.com/apache/iceberg/pull/1243#discussion_r460739962



##########
File path: mr/src/main/java/org/apache/iceberg/mr/Catalogs.java
##########
@@ -0,0 +1,110 @@
+/*
+ * 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;
+
+import java.util.Optional;
+import java.util.Properties;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.catalog.Catalog;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.common.DynConstructors;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+import org.apache.iceberg.hadoop.HadoopCatalog;
+import org.apache.iceberg.hadoop.HadoopTables;
+import org.apache.iceberg.hive.HiveCatalogs;
+import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+
+public final class Catalogs {
+
+  private static final String HADOOP = "hadoop";
+  private static final String HIVE = "hive";
+
+  private static final String NAME = "name";
+  private static final String LOCATION = "location";
+
+  private Catalogs() {}
+
+  /**
+   * Load an Iceberg table using the catalog and table identifier (or table path) specified by the configuration.
+   * Catalog resolution happens in this order:
+   * 1. Custom catalog if specified by {@link InputFormatConfig#CATALOG_LOADER_CLASS}
+   * 2. Hadoop or Hive catalog if specified by {@link InputFormatConfig#CATALOG}
+   * 3. Hadoop Tables
+   * @param conf a Hadoop conf
+   * @return an Iceberg table
+   */
+  public static Table loadTable(Configuration conf) {
+    // A bit of a hack to make this function work transparently with Hive without having to remap the "name" and
+    // "location" properties.
+    if (HiveConf.getVar(conf, HiveConf.ConfVars.HIVEQUERYID).length() > 0) {
+      return loadTable(conf, conf.get(NAME), conf.get(LOCATION));

Review comment:
       A useful test could be to add a HiveRunner test which does a join between multiple tables, each one loaded with a different catalog. We definitely found some issues in our earlier implementation of this that didn't hold once more than one table was involved in the query.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org