Skip to content

Commit

Permalink
fix comment
Browse files Browse the repository at this point in the history
  • Loading branch information
FANNG1 committed Oct 20, 2024
1 parent f5beda9 commit 9a5a18f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.Scheduler;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.util.Map;
Expand Down Expand Up @@ -92,17 +91,21 @@ public IcebergCatalogWrapperManager(Map<String, String> properties) {
* @return the instance of IcebergCatalogWrapper.
*/
public IcebergCatalogWrapper getOps(String rawPrefix) {
String catalogName = getCatalogName(rawPrefix);
IcebergCatalogWrapper tableOps =
String catalogName = IcebergRestUtils.getCatalogName(rawPrefix);
return getCatalogWrapper(catalogName);
}

public IcebergCatalogWrapper getCatalogWrapper(String catalogName) {
IcebergCatalogWrapper catalogWrapper =
icebergCatalogWrapperCache.get(catalogName, k -> createCatalogWrapper(catalogName));
// Reload conf to reset UserGroupInformation or icebergTableOps will always use
// Simple auth.
tableOps.reloadHadoopConf();
return tableOps;
catalogWrapper.reloadHadoopConf();
return catalogWrapper;
}

public CredentialProvider getCredentialProvider(String prefix) {
String catalogName = getCatalogName(prefix);
String catalogName = IcebergRestUtils.getCatalogName(prefix);
return credentialProviderManager.getCredentialProvider(catalogName);
}

Expand All @@ -128,17 +131,6 @@ private IcebergCatalogWrapper createCatalogWrapper(String catalogName) {
return createIcebergCatalogWrapper(icebergConfig.get());
}

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 IcebergCatalogConfigProvider createIcebergCatalogConfigProvider(
Map<String, String> properties) {
String providerName =
Expand All @@ -154,7 +146,6 @@ private IcebergCatalogConfigProvider createIcebergCatalogConfigProvider(
}
}


private void closeIcebergCatalogWrapper(IcebergCatalogWrapper catalogWrapper) {
try {
catalogWrapper.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,6 @@ public static Instant calculateNewTimestamp(Instant currentTimestamp, int hours)
return nextHourDateTime.atZone(ZoneId.systemDefault()).toInstant();
}

public static String getCatalogName(String rawPrefix) {
String prefix = normalizePrefix(rawPrefix);
Preconditions.checkArgument(
!IcebergConstants.ICEBERG_REST_DEFAULT_CATALOG.equals(prefix),
String.format("%s is conflict with reserved key, please replace it", prefix));
if (StringUtils.isBlank(prefix)) {
return IcebergConstants.ICEBERG_REST_DEFAULT_CATALOG;
}
return prefix;
}

public static NameIdentifier getGravitinoNameIdentifier(
String catalogName, TableIdentifier icebergIdentifier) {
// todo(fanng): use a more general way to get metalake
Expand All @@ -104,17 +93,15 @@ public static NameIdentifier getGravitinoNameIdentifier(
return NameIdentifier.of(catalogNSTable);
}

// remove the last '/' from the prefix, for example transform 'iceberg_catalog/' to
// 'iceberg_catalog'
private static String normalizePrefix(String rawPrefix) {
if (StringUtils.isBlank(rawPrefix)) {
return rawPrefix;
} else {
// rawPrefix is a string matching ([^/]*/) which end with /
Preconditions.checkArgument(
rawPrefix.endsWith("/"), String.format("rawPrefix %s format is illegal", rawPrefix));
return rawPrefix.substring(0, rawPrefix.length() - 1);
public static String getCatalogName(String rawPrefix) {
String catalogName = normalizePrefix(rawPrefix);
Preconditions.checkArgument(
!IcebergConstants.ICEBERG_REST_DEFAULT_CATALOG.equals(catalogName),
String.format("%s is conflict with default catalog name, please replace it", catalogName));
if (StringUtils.isBlank(catalogName)) {
return IcebergConstants.ICEBERG_REST_DEFAULT_CATALOG;
}
return catalogName;
}

public static <T> T cloneIcebergRESTObject(Object message, Class<T> className) {
Expand All @@ -126,4 +113,17 @@ public static <T> T cloneIcebergRESTObject(Object message, Class<T> className) {
throw new RuntimeException(e);
}
}

// remove the last '/' from the prefix, for example transform 'iceberg_catalog/' to
// 'iceberg_catalog'
private static String normalizePrefix(String rawPrefix) {
if (StringUtils.isBlank(rawPrefix)) {
return rawPrefix;
} else {
// rawPrefix is a string matching ([^/]*/) which end with /
Preconditions.checkArgument(
rawPrefix.endsWith("/"), String.format("rawPrefix %s format is illegal", rawPrefix));
return rawPrefix.substring(0, rawPrefix.length() - 1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
import org.apache.gravitino.iceberg.service.IcebergCatalogWrapperManager;
import org.apache.gravitino.iceberg.service.IcebergExceptionMapper;
import org.apache.gravitino.iceberg.service.IcebergObjectMapperProvider;
import org.apache.gravitino.iceberg.service.extension.DummyCredentialProvider;
import org.apache.gravitino.iceberg.service.dispatcher.IcebergTableEventDispatcher;
import org.apache.gravitino.iceberg.service.dispatcher.IcebergTableOperationDispatcher;
import org.apache.gravitino.iceberg.service.dispatcher.IcebergTableOperationExecutor;
import org.apache.gravitino.iceberg.service.extension.DummyCredentialProvider;
import org.apache.gravitino.iceberg.service.metrics.IcebergMetricsManager;
import org.apache.gravitino.listener.EventBus;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
Expand Down

0 comments on commit 9a5a18f

Please sign in to comment.