dimas-b commented on code in PR #1170:
URL: https://github.com/apache/polaris/pull/1170#discussion_r1999703966
##########
build-logic/src/main/kotlin/polaris-java.gradle.kts:
##########
@@ -160,6 +160,45 @@ tasks.withType(Jar::class).configureEach {
}
}
+class StaleBehaviorChangeConfigurationChecker(private val appVersion: String)
: FormatterFunc {
+
+ // Helper function for spotless to check for stale
BehaviorChangeConfigurations
+ fun isStaleVersion(
+ annotatedVersion: String,
+ expiresVersion: String?,
+ polarisVersion: String,
+ ): Boolean {
+ val (majorA, minorA, patchA) = annotatedVersion.split(".").map {
it.toInt() }
+ if (expiresVersion == null) {
+ val (majorB, minorB, _) = polarisVersion.split(".").map { it.toInt() }
+ return (majorB > majorA || (majorB == majorA && minorB > minorA + 1))
+ } else {
+ val (majorB, minorB, patchB) = expiresVersion.split(".").map {
it.toInt() }
+ return (majorA > majorB ||
+ (majorA == majorB && minorA > minorB) ||
+ (majorA == majorB && minorA == minorB && patchB > patchA))
Review Comment:
should it be `&& patchA > patchB`?
##########
build-logic/src/main/kotlin/polaris-java.gradle.kts:
##########
@@ -160,6 +160,45 @@ tasks.withType(Jar::class).configureEach {
}
}
+class StaleBehaviorChangeConfigurationChecker(private val appVersion: String)
: FormatterFunc {
+
+ // Helper function for spotless to check for stale
BehaviorChangeConfigurations
+ fun isStaleVersion(
+ annotatedVersion: String,
+ expiresVersion: String?,
+ polarisVersion: String,
+ ): Boolean {
+ val (majorA, minorA, patchA) = annotatedVersion.split(".").map {
it.toInt() }
+ if (expiresVersion == null) {
+ val (majorB, minorB, _) = polarisVersion.split(".").map { it.toInt() }
+ return (majorB > majorA || (majorB == majorA && minorB > minorA + 1))
+ } else {
+ val (majorB, minorB, patchB) = expiresVersion.split(".").map {
it.toInt() }
+ return (majorA > majorB ||
Review Comment:
Should we compare `expiresVersion` to `polarisVersion`?
##########
polaris-core/src/main/java/org/apache/polaris/core/config/BehaviorChangeProcessor.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.core.config;
+
+import java.util.Set;
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedSourceVersion;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.util.Elements;
+import javax.tools.Diagnostic;
+
+@SupportedAnnotationTypes("BehaviorChange")
+@SupportedSourceVersion(SourceVersion.RELEASE_8)
+public class BehaviorChangeProcessor extends AbstractProcessor {
+
+ @Override
+ public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
Review Comment:
Would it be possible to move version/expiry checks here? It think it would
be nicer from the overall design POV.
Build scripts could probably inject "current version" into system
properties. WDYT?
##########
build-logic/src/main/kotlin/polaris-java.gradle.kts:
##########
@@ -160,6 +160,45 @@ tasks.withType(Jar::class).configureEach {
}
}
+class StaleBehaviorChangeConfigurationChecker(private val appVersion: String)
: FormatterFunc {
+
+ // Helper function for spotless to check for stale
BehaviorChangeConfigurations
+ fun isStaleVersion(
+ annotatedVersion: String,
+ expiresVersion: String?,
+ polarisVersion: String,
+ ): Boolean {
+ val (majorA, minorA, patchA) = annotatedVersion.split(".").map {
it.toInt() }
+ if (expiresVersion == null) {
+ val (majorB, minorB, _) = polarisVersion.split(".").map { it.toInt() }
+ return (majorB > majorA || (majorB == majorA && minorB > minorA + 1))
Review Comment:
Is it possible to have only on place for comparing versions, but derive the
"expires" version from the "added" version automatically?
##########
polaris-core/src/main/java/org/apache/polaris/core/config/BehaviorChangeConfiguration.java:
##########
@@ -37,9 +37,10 @@ protected BehaviorChangeConfiguration(
super(key, description, defaultValue, catalogConfig);
}
+ @BehaviorChange(since = "1.0.0")
public static final BehaviorChangeConfiguration<Boolean>
VALIDATE_VIEW_LOCATION_OVERLAP =
PolarisConfiguration.<Boolean>builder()
- .key("STORAGE_CREDENTIAL_CACHE_DURATION_SECONDS")
+ .key("VALIDATE_VIEW_LOCATION_OVERLAP")
Review Comment:
WDYT about making this a small separate PR, which this one is still in
review?
##########
build-logic/src/main/kotlin/polaris-java.gradle.kts:
##########
@@ -160,6 +160,45 @@ tasks.withType(Jar::class).configureEach {
}
}
+class StaleBehaviorChangeConfigurationChecker(private val appVersion: String)
: FormatterFunc {
+
+ // Helper function for spotless to check for stale
BehaviorChangeConfigurations
+ fun isStaleVersion(
+ annotatedVersion: String,
+ expiresVersion: String?,
+ polarisVersion: String,
+ ): Boolean {
+ val (majorA, minorA, patchA) = annotatedVersion.split(".").map {
it.toInt() }
+ if (expiresVersion == null) {
+ val (majorB, minorB, _) = polarisVersion.split(".").map { it.toInt() }
+ return (majorB > majorA || (majorB == majorA && minorB > minorA + 1))
+ } else {
+ val (majorB, minorB, patchB) = expiresVersion.split(".").map {
it.toInt() }
+ return (majorA > majorB ||
+ (majorA == majorB && minorA > minorB) ||
+ (majorA == majorB && minorA == minorB && patchB > patchA))
+ }
+ }
+
+ override fun apply(input: String): String {
+ val versionRegex =
+
"""@BehaviorChangeScope\s*\(\s*since\s*=\s*"(\d+\.\d+\.\d+)"(?:\s*,\s*expires\s*=\s*"(\d+\.\d+\.\d+)")?\s*\)"""
Review Comment:
Will it work if the annotation is split across multiple lines?
##########
polaris-core/src/main/java/org/apache/polaris/core/config/BehaviorChangeProcessor.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.core.config;
+
+import java.util.Set;
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedSourceVersion;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.util.Elements;
+import javax.tools.Diagnostic;
+
+@SupportedAnnotationTypes("BehaviorChange")
+@SupportedSourceVersion(SourceVersion.RELEASE_8)
+public class BehaviorChangeProcessor extends AbstractProcessor {
+
+ @Override
+ public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
+
+ Elements elementUtils = processingEnv.getElementUtils();
+
+ for (Element element : roundEnv.getRootElements()) {
+ if (element.getKind() == ElementKind.CLASS) {
+ TypeElement typeElement = (TypeElement) element;
+ for (Element enclosedElement : typeElement.getEnclosedElements()) {
+ if (enclosedElement.getKind() == ElementKind.FIELD) {
+ VariableElement field = (VariableElement) enclosedElement;
+ TypeMirror fieldType = field.asType();
+
+ if (isBehaviorChangeConfiguration(fieldType, elementUtils)) {
+ if (field.getAnnotation(BehaviorChange.class) == null) {
+ processingEnv
+ .getMessager()
+ .printMessage(
+ Diagnostic.Kind.ERROR,
+ "Field "
+ + field.getSimpleName()
+ + " of type BehaviorChangeConfiguration<?> must be
annotated with @BehaviorChange",
+ field);
+ } else {
+ processingEnv
+ .getMessager()
+ .printMessage(
+ Diagnostic.Kind.NOTE,
+ "Field "
+ + field.getSimpleName()
+ + " is correctly annotated with @BehaviorChange",
Review Comment:
Is it worth logging?
--
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]