rymurr commented on a change in pull request #1875:
URL: https://github.com/apache/iceberg/pull/1875#discussion_r543670252
##########
File path: spark/src/main/java/org/apache/iceberg/spark/SparkUtil.java
##########
@@ -61,4 +65,40 @@ public static void validatePartitionTransforms(PartitionSpec
spec) {
String.format("Cannot write using unsupported transforms: %s",
unsupported));
}
}
+
+ /**
+ * A modified version of Spark's LookupCatalog.CatalogAndIdentifier.unapply
+ * Attempts to find the catalog and identifier a multipart identifier
represents
+ * @param nameParts Multipart identifier representing a table
+ * @return The CatalogPlugin and Identifier for the table
+ */
+ public static <C, T> Pair<C,T> catalogAndIdentifier(List<String> nameParts,
+ Function<String, C>
catalog,
+ IdentiferFunction<T>
identifer,
+ String[]
currentNamespace) {
Review comment:
fixe
##########
File path: spark/src/main/java/org/apache/iceberg/spark/SparkUtil.java
##########
@@ -61,4 +65,40 @@ public static void validatePartitionTransforms(PartitionSpec
spec) {
String.format("Cannot write using unsupported transforms: %s",
unsupported));
}
}
+
+ /**
+ * A modified version of Spark's LookupCatalog.CatalogAndIdentifier.unapply
+ * Attempts to find the catalog and identifier a multipart identifier
represents
+ * @param nameParts Multipart identifier representing a table
+ * @return The CatalogPlugin and Identifier for the table
+ */
+ public static <C, T> Pair<C,T> catalogAndIdentifier(List<String> nameParts,
+ Function<String, C>
catalog,
+ IdentiferFunction<T>
identifer,
+ String[]
currentNamespace) {
Review comment:
fixed
##########
File path:
spark2/src/main/java/org/apache/iceberg/spark/source/CustomCatalogs.java
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.spark.source;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.iceberg.CatalogUtil;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.catalog.Catalog;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.TableIdentifier;
+import
org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
+import org.apache.iceberg.relocated.com.google.common.base.Splitter;
+import org.apache.iceberg.spark.SparkUtil;
+import org.apache.iceberg.util.Pair;
+import org.apache.spark.SparkConf;
+import org.apache.spark.sql.SparkSession;
+
+public final class CustomCatalogs {
+ private static final Cache<Pair<SparkSession, String>, Catalog>
CATALOG_CACHE = Caffeine.newBuilder().softValues().build();
+
+ public static final String ICEBERG_DEFAULT_CATALOG = "default_catalog";
+ public static final String ICEBERG_CATALOG_PREFIX = "spark.sql.catalog";
+
+ private CustomCatalogs() {
+ }
+
+ /**
+ * Build an Iceberg {@link Catalog} to be used by this Spark source adapter.
+ *
+ * <p>
+ * The cache is to facilitate reuse of catalogs, especially if wrapped in
CachingCatalog. For non-Hive catalogs all
+ * custom parameters passed to the catalog are considered in the cache
key. Hive catalogs only cache based on
+ * the Metastore URIs as per previous behaviour.
+ * </p>
+ *
+ * @param spark Spark Session
+ * @param name Catalog Name
+ * @return an Iceberg catalog
+ */
+ public static Catalog buildIcebergCatalog(SparkSession spark, String name) {
Review comment:
fixed
##########
File path:
spark2/src/main/java/org/apache/iceberg/spark/source/IcebergSource.java
##########
@@ -24,16 +24,16 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.iceberg.Schema;
import org.apache.iceberg.Table;
+import org.apache.iceberg.catalog.Catalog;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.encryption.EncryptionManager;
import org.apache.iceberg.hadoop.HadoopTables;
-import org.apache.iceberg.hive.HiveCatalog;
-import org.apache.iceberg.hive.HiveCatalogs;
import org.apache.iceberg.io.FileIO;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
import org.apache.iceberg.spark.SparkSchemaUtil;
import org.apache.iceberg.spark.SparkUtil;
import org.apache.iceberg.types.TypeUtil;
+import org.apache.iceberg.util.Pair;
Review comment:
fixed
----------------------------------------------------------------
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]