dimas-b commented on code in PR #3573:
URL: https://github.com/apache/polaris/pull/3573#discussion_r2774894010
##########
polaris-core/src/main/java/org/apache/polaris/core/config/RealmConfigImpl.java:
##########
@@ -18,43 +18,105 @@
*/
package org.apache.polaris.core.config;
+import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
import java.util.Map;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.entity.CatalogEntity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class RealmConfigImpl implements RealmConfig {
+ private static final Logger LOGGER =
LoggerFactory.getLogger(RealmConfigImpl.class);
- private final PolarisConfigurationStore configurationStore;
+ private final RealmConfigurationSource configurationSource;
private final RealmContext realmContext;
- public RealmConfigImpl(PolarisConfigurationStore configurationStore,
RealmContext realmContext) {
- this.configurationStore = configurationStore;
+ public RealmConfigImpl(RealmConfigurationSource configurationSource,
RealmContext realmContext) {
+ this.configurationSource = configurationSource;
this.realmContext = realmContext;
}
+ @SuppressWarnings("removal")
@Override
public <T> @Nullable T getConfig(String configName) {
- return configurationStore.getConfiguration(realmContext, configName);
+ @SuppressWarnings("unchecked")
+ T value = (T) configurationSource.getConfigValue(realmContext, configName);
+ return value;
}
+ @SuppressWarnings("removal")
@Override
public <T> T getConfig(String configName, T defaultValue) {
- return configurationStore.getConfiguration(realmContext, configName,
defaultValue);
+ @SuppressWarnings("unchecked")
+ T value = (T) getConfig(configName);
+ if (value == null) {
+ return defaultValue;
+ }
+ return value;
}
@Override
public <T> T getConfig(PolarisConfiguration<T> config) {
- return configurationStore.getConfiguration(realmContext, config);
+ return getConfig(config, Collections.emptyMap());
}
@Override
public <T> T getConfig(PolarisConfiguration<T> config, CatalogEntity
catalogEntity) {
- return configurationStore.getConfiguration(realmContext, catalogEntity,
config);
+ return getConfig(config, catalogEntity.getPropertiesAsMap());
}
@Override
public <T> T getConfig(PolarisConfiguration<T> config, Map<String, String>
catalogProperties) {
- return configurationStore.getConfiguration(realmContext,
catalogProperties, config);
+ Object propertyValue = null;
+ if (config.hasCatalogConfig() || config.hasCatalogConfigUnsafe()) {
+ if (config.hasCatalogConfig()) {
+ propertyValue = catalogProperties.get(config.catalogConfig());
+ }
+ if (propertyValue == null) {
+ if (config.hasCatalogConfigUnsafe()) {
+ propertyValue = catalogProperties.get(config.catalogConfigUnsafe());
+ }
+ if (propertyValue != null) {
+ LOGGER.warn(
+ String.format(
+ "Deprecated config %s is in use and will be removed in a
future version",
+ config.catalogConfigUnsafe()));
+ }
+ }
+ }
+
+ if (propertyValue == null) {
+ propertyValue = configurationSource.getConfigValue(realmContext,
config.key());
+ }
+
+ return tryCast(config, propertyValue);
+ }
+
+ /**
+ * In some cases, we may extract a value that doesn't match the expected
type for a config. This
+ * method can be used to attempt to force-cast it using `String.valueOf`
+ */
+ private <T> @Nonnull T tryCast(PolarisConfiguration<T> config, Object value)
{
+ if (value == null) {
+ return config.defaultValue();
+ }
+
+ if (config.defaultValue() instanceof Boolean) {
+ return config.cast(Boolean.valueOf(String.valueOf(value)));
Review Comment:
#3688
--
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]