flyrain commented on code in PR #282:
URL: https://github.com/apache/polaris/pull/282#discussion_r1762005016
##########
polaris-core/src/main/java/org/apache/polaris/core/PolarisCallContext.java:
##########
@@ -21,56 +21,44 @@
import java.time.Clock;
import java.time.ZoneId;
import org.apache.polaris.core.persistence.PolarisMetaStoreSession;
+import org.apache.polaris.immutables.PolarisImmutable;
+import org.immutables.value.Value;
import org.jetbrains.annotations.NotNull;
/**
* The Call context is allocated each time a new REST request is processed. It
contains instances of
* low-level services required to process that request
*/
-public class PolarisCallContext {
+@PolarisImmutable
+public interface PolarisCallContext {
- // meta store which is used to persist Polaris entity metadata
- private final PolarisMetaStoreSession metaStore;
+ @Value.Parameter(order = 0)
Review Comment:
Is the order needed here? Looks like the constructor isn't used anywhere.
##########
polaris-core/src/main/java/org/apache/polaris/core/PolarisConfiguration.java:
##########
@@ -19,89 +19,55 @@
package org.apache.polaris.core;
import java.util.Optional;
+import org.apache.polaris.immutables.PolarisImmutable;
+import org.immutables.value.Value;
-public class PolarisConfiguration<T> {
-
- public final String key;
- public final String description;
- public final T defaultValue;
- private final Optional<String> catalogConfigImpl;
- private final Class<T> typ;
-
- @SuppressWarnings("unchecked")
- public PolarisConfiguration(
- String key, String description, T defaultValue, Optional<String>
catalogConfig) {
- this.key = key;
- this.description = description;
- this.defaultValue = defaultValue;
- this.catalogConfigImpl = catalogConfig;
- this.typ = (Class<T>) defaultValue.getClass();
- }
+@PolarisImmutable
+public interface PolarisConfiguration<T> {
- public boolean hasCatalogConfig() {
- return catalogConfigImpl.isPresent();
- }
+ String key();
+
+ String description();
+
+ T defaultValue();
+
+ Optional<String> catalogConfig();
- public String catalogConfig() {
- return catalogConfigImpl.orElseThrow(
- () ->
- new IllegalStateException(
- "Attempted to read a catalog config key from a configuration
that doesn't have one."));
+ @Value.Derived
+ default boolean hasCatalogConfig() {
+ return catalogConfig().isPresent();
}
- T cast(Object value) {
- return this.typ.cast(value);
+ @Value.Lazy
Review Comment:
Minor: this suggestion is NOT applied
##########
polaris-immutables/src/main/java/org/apache/polaris/immutables/PolarisImmutable.java:
##########
@@ -0,0 +1,39 @@
+/*
+ * 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.immutables;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+import org.immutables.value.Value;
+
+/**
+ * A <a
href="http://immutables.github.io/style.html#custom-immutable-annotation">Custom
+ * {@code @Value.Immutable}</a> using {@code lazyhash=true,
forceJacksonPropertyNames = false,
+ * clearBuilder = true, depluralize = true, and JavaBeans-style getters}.
+ */
Review Comment:
I think we don't need to repeat the properties in the Java doc. Maybe we
could add a bit reason why we choose these properties in the doc.
##########
polaris-service/src/main/java/org/apache/polaris/service/context/PolarisCallContextCatalogFactory.java:
##########
@@ -82,8 +82,6 @@ public Catalog createCallContextCatalog(
taskExecutor,
fileIOFactory);
-
context.contextVariables().put(CallContext.REQUEST_PATH_CATALOG_INSTANCE_KEY,
catalogInstance);
Review Comment:
Curious how the catalogInstance is set in `context` if we remove this line.
--
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]