FANNG1 commented on code in PR #4273:
URL: https://github.com/apache/gravitino/pull/4273#discussion_r1714955148


##########
iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/ops/IcebergTableOpsManager.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.gravitino.iceberg.common.ops;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
+import org.apache.commons.lang.StringUtils;
+import org.apache.gravitino.catalog.lakehouse.iceberg.IcebergConstants;
+import org.apache.gravitino.iceberg.common.IcebergConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class IcebergTableOpsManager implements AutoCloseable {
+  public static final Logger LOG = 
LoggerFactory.getLogger(IcebergTableOpsManager.class);
+
+  private static final ImmutableMap<String, String> 
ICEBERG_TABLE_OPS_PROVIDER_NAMES =
+      ImmutableMap.of(
+          
ConfigBasedIcebergTableOpsProvider.CONFIG_BASE_ICEBERG_TABLE_OPS_PROVIDER_NAME,
+          ConfigBasedIcebergTableOpsProvider.class.getCanonicalName());
+
+  private final Cache<String, IcebergTableOps> icebergTableOpsCache;
+
+  private IcebergTableOpsProvider provider;
+
+  public IcebergTableOpsManager(Map<String, String> properties) {
+    this.icebergTableOpsCache = Caffeine.newBuilder().build();
+    this.provider = createProvider(properties);
+    this.provider.initialize(properties);
+  }
+
+  /**
+   * @param rawPrefix The path parameter is passed by a Jetty handler. The 
pattern is matching
+   *     ([^/]*\/), end with /
+   * @return the instance of IcebergTableOps.
+   */
+  public IcebergTableOps getOps(String rawPrefix) {
+    String catalogName = getCatalogName(rawPrefix);
+    return icebergTableOpsCache.get(catalogName, k -> 
provider.getIcebergTableOps(catalogName));
+  }
+
+  @VisibleForTesting
+  public void setIcebergTableOpsProvider(IcebergTableOpsProvider provider) {
+    this.provider = provider;
+  }
+
+  private String getCatalogName(String rawPrefix) {
+    String prefix = shelling(rawPrefix);
+    Preconditions.checkArgument(
+        !IcebergConstants.GRAVITINO_DEFAULT_CATALOG.equals(prefix),
+        String.format("%s is conflict with reserved key, please replace it", 
prefix));
+    if (StringUtils.isBlank(prefix)) {
+      return IcebergConstants.GRAVITINO_DEFAULT_CATALOG;
+    }
+    return prefix;
+  }
+
+  private IcebergTableOpsProvider createProvider(Map<String, String> 
properties) {
+    String providerName =

Review Comment:
   We'd better support user pass a custom catalog provider with class names



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

Reply via email to