snazy commented on code in PR #3573:
URL: https://github.com/apache/polaris/pull/3573#discussion_r2772628625
##########
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:
Yea - but I think it needs to be tackled in a follow-up.
Configurations are often used on hot code path.
Same for below.
##########
polaris-core/src/test/java/org/apache/polaris/core/storage/cache/StorageCredentialCacheTest.java:
##########
@@ -225,18 +225,8 @@ public void testCacheMissForAnotherPrincipal() {
Mockito.when(storageCredentialsVendor.getRealmConfig())
.thenReturn(
new RealmConfigImpl(
- new PolarisConfigurationStore() {
- @SuppressWarnings("unchecked")
- @Override
- public String getConfiguration(@Nonnull RealmContext ctx,
String configName) {
- if (configName.equals(
-
FeatureConfiguration.INCLUDE_PRINCIPAL_NAME_IN_SUBSCOPED_CREDENTIAL
- .key())) {
- return "true";
- }
- return null;
- }
- },
+ (rc, name) ->
+
Map.of(INCLUDE_PRINCIPAL_NAME_IN_SUBSCOPED_CREDENTIAL.key(), "true").get(name),
Review Comment:
Maybe, but Alex' way is clearer.
(Troll: Without a formatter, we could squeeze the whole file into a single
line :P )
##########
runtime/service/src/main/java/org/apache/polaris/service/config/PolarisConfigurationStoreBridge.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.polaris.service.config;
+
+import jakarta.annotation.Nonnull;
+import jakarta.annotation.Nullable;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import org.apache.polaris.core.context.RealmContext;
+
+@SuppressWarnings("removal")
+@ApplicationScoped
+public class PolarisConfigurationStoreBridge
Review Comment:
What's the use case of this application-scoped bean?
I only see one usage in a test. Maybe refactor the test or move this type to
`testFixtures`.
##########
polaris-core/src/main/java/org/apache/polaris/core/PolarisCallContext.java:
##########
@@ -34,23 +34,36 @@ public class PolarisCallContext implements CallContext {
// meta store which is used to persist Polaris entity metadata
private final BasePersistence metaStore;
- private final PolarisConfigurationStore configurationStore;
+ private final RealmConfigurationSource configurationSource;
private final RealmContext realmContext;
private final RealmConfig realmConfig;
+ /**
+ * @deprecated Use {@link
PolarisCallContext#PolarisCallContext(RealmContext, BasePersistence,
+ * RealmConfigurationSource)}.
+ */
+ @SuppressWarnings("removal")
+ @Deprecated(forRemoval = true)
public PolarisCallContext(
@Nonnull RealmContext realmContext,
@Nonnull BasePersistence metaStore,
- @Nonnull PolarisConfigurationStore configurationStore) {
+ @Nonnull org.apache.polaris.core.config.PolarisConfigurationStore
configurationStore) {
Review Comment:
> IntelliJ warns about deprecation on the import statement
This is strange, because that Java 8 legacy was removed via [JEP
211](https://openjdk.org/jeps/211).
--
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]