in service/common/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalog.java [238:311]
public void initialize(String name, Map<String, String> properties) {
Preconditions.checkState(
this.catalogName.equals(name),
"Tried to initialize catalog as name %s but already constructed with name %s",
name,
this.catalogName);
// Ensure catalogProperties is assigned before calling metricsReporter() for proper
// functionality.
catalogProperties = properties;
// Base location from catalogEntity is primary source of truth, otherwise fall through
// to the same key from the properties map, and finally fall through to WAREHOUSE_LOCATION.
String baseLocation =
Optional.ofNullable(catalogEntity.getDefaultBaseLocation())
.orElse(
properties.getOrDefault(
CatalogEntity.DEFAULT_BASE_LOCATION_KEY,
properties.getOrDefault(CatalogProperties.WAREHOUSE_LOCATION, "")));
this.defaultBaseLocation = baseLocation.replaceAll("/*$", "");
Boolean allowSpecifyingFileIoImpl =
getBooleanContextConfiguration(
ALLOW_SPECIFYING_FILE_IO_IMPL, ALLOW_SPECIFYING_FILE_IO_IMPL_DEFAULT);
PolarisStorageConfigurationInfo storageConfigurationInfo =
catalogEntity.getStorageConfigurationInfo();
if (properties.containsKey(CatalogProperties.FILE_IO_IMPL)) {
ioImplClassName = properties.get(CatalogProperties.FILE_IO_IMPL);
if (!Boolean.TRUE.equals(allowSpecifyingFileIoImpl)) {
throw new ValidationException(
"Cannot set property '%s' to '%s' for this catalog.",
CatalogProperties.FILE_IO_IMPL, ioImplClassName);
}
LOGGER.debug(
"Allowing overriding ioImplClassName to {} for storageConfiguration {}",
ioImplClassName,
storageConfigurationInfo);
} else {
if (storageConfigurationInfo != null) {
ioImplClassName = storageConfigurationInfo.getFileIoImplClassName();
LOGGER.debug(
"Resolved ioImplClassName {} from storageConfiguration {}",
ioImplClassName,
storageConfigurationInfo);
} else {
LOGGER.warn(
"Cannot resolve property '{}' for null storageConfiguration.",
CatalogProperties.FILE_IO_IMPL);
}
}
callContext.closeables().addCloseable(this);
this.closeableGroup = new CloseableGroup();
closeableGroup.addCloseable(metricsReporter());
closeableGroup.setSuppressCloseFailure(true);
tableDefaultProperties =
PropertyUtil.propertiesWithPrefix(properties, CatalogProperties.TABLE_DEFAULT_PREFIX);
Boolean initializeDefaultCatalogFileioForTest =
getBooleanContextConfiguration(
INITIALIZE_DEFAULT_CATALOG_FILEIO_FOR_TEST,
INITIALIZE_DEFAULT_CATALOG_FILEIO_FOR_TEST_DEFAULT);
if (Boolean.TRUE.equals(initializeDefaultCatalogFileioForTest)) {
LOGGER.debug(
"Initializing a default catalogFileIO with properties {}", tableDefaultProperties);
this.catalogFileIO = loadFileIO(ioImplClassName, tableDefaultProperties);
closeableGroup.addCloseable(this.catalogFileIO);
} else {
LOGGER.debug("Not initializing default catalogFileIO");
this.catalogFileIO = null;
}
}