Copilot commented on code in PR #11707:
URL: https://github.com/apache/gravitino/pull/11707#discussion_r3426028624
##########
catalogs/catalog-hive/src/main/java/org/apache/gravitino/catalog/hive/HiveCatalogCapability.java:
##########
@@ -42,15 +42,16 @@ public CapabilityResult columnDefaultValue() {
@Override
public CapabilityResult caseSensitiveOnName(Scope scope) {
- switch (scope) {
- case SCHEMA:
- case TABLE:
- case COLUMN:
- // Hive is case insensitive, see
- //
https://cwiki.apache.org/confluence/display/Hive/User+FAQ#UserFAQ-AreHiveSQLidentifiers(e.g.tablenames,columnnames,etc)casesensitive?
- return CapabilityResult.unsupported("Hive is case insensitive.");
- default:
- return CapabilityResult.SUPPORTED;
+ // Use if-else instead of switch-on-enum to avoid the compiler-generated
synthetic class $1.
+ // SchemaNormalizeDispatcher calls this method outside the
IsolatedClassLoader.withClassLoader()
+ // boundary. A switch-on-enum causes the JVM to load $1 via the server
classloader, which
+ // cannot find it, and the JVM permanently caches the failure for the
process lifetime.
+ // if-else with == compiles to if_acmpeq (reference comparison) with no
synthetic class.
+ // Hive is case insensitive, see
+ //
https://cwiki.apache.org/confluence/display/Hive/User+FAQ#UserFAQ-AreHiveSQLidentifiers(e.g.tablenames,columnnames,etc)casesensitive?
+ if (scope == Scope.SCHEMA || scope == Scope.TABLE || scope ==
Scope.COLUMN) {
+ return CapabilityResult.unsupported("Hive is case insensitive.");
}
+ return CapabilityResult.SUPPORTED;
Review Comment:
The new if/else implementation changes null-handling semantics: `switch
(scope)` would throw `NullPointerException` when `scope` is null, but `scope ==
...` will fall through and return `SUPPORTED`. If `scope` is expected to be
non-null, add an explicit null check to preserve fail-fast behavior (and to
keep behavior consistent with the old switch).
##########
catalogs/catalog-hive/src/test/java/org/apache/gravitino/catalog/hive/TestHiveCatalogCapability.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.gravitino.catalog.hive;
+
+import org.apache.gravitino.connector.capability.Capability;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class TestHiveCatalogCapability {
+
+ private HiveCatalogCapability capability;
+
+ @BeforeEach
+ public void setUp() {
+ capability = new HiveCatalogCapability();
+ }
+
+ @Test
+ public void testCaseSensitiveOnNameForCaseInsensitiveScopes() {
+ // Hive is case insensitive for SCHEMA, TABLE and COLUMN names.
+
Assertions.assertFalse(capability.caseSensitiveOnName(Capability.Scope.SCHEMA).supported());
+
Assertions.assertFalse(capability.caseSensitiveOnName(Capability.Scope.TABLE).supported());
+
Assertions.assertFalse(capability.caseSensitiveOnName(Capability.Scope.COLUMN).supported());
+ }
+
+ @Test
+ public void testCaseSensitiveOnNameForCaseSensitiveScopes() {
+ // All other scopes are case sensitive (default behaviour).
+
Assertions.assertTrue(capability.caseSensitiveOnName(Capability.Scope.FILESET).supported());
+
Assertions.assertTrue(capability.caseSensitiveOnName(Capability.Scope.TOPIC).supported());
+
Assertions.assertTrue(capability.caseSensitiveOnName(Capability.Scope.PARTITION).supported());
+
Assertions.assertTrue(capability.caseSensitiveOnName(Capability.Scope.MODEL).supported());
+ }
+
+ @Test
+ public void testCaseSensitiveOnNameSyntheticClassAbsent() throws
ClassNotFoundException {
Review Comment:
`testCaseSensitiveOnNameSyntheticClassAbsent` declares `throws
ClassNotFoundException`, but the test already asserts that exception via
`assertThrows`. Removing the throws clause makes the intent clearer and avoids
implying the exception can escape the test.
--
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]