This is an automated email from the ASF dual-hosted git repository.
menghaoranss pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 66e57fbc1ad Enforce lower case identifier policy for hive (#39290)
66e57fbc1ad is described below
commit 66e57fbc1ad3684190c7f49028824006f36e79fc
Author: Haoran Meng <[email protected]>
AuthorDate: Fri Jul 31 18:32:50 2026 +0800
Enforce lower case identifier policy for hive (#39290)
---
.../metadata/database/HiveDatabaseMetaData.java | 2 +-
.../HiveIdentifierCasePolicyProvider.java | 39 +++++++++++++++
...etadata.identifier.IdentifierCasePolicyProvider | 18 +++++++
.../database/HiveDatabaseMetaDataTest.java | 2 +-
.../HiveIdentifierCasePolicyProviderTest.java | 58 ++++++++++++++++++++++
5 files changed, 117 insertions(+), 2 deletions(-)
diff --git
a/database/connector/dialect/hive/src/main/java/org/apache/shardingsphere/database/connector/hive/metadata/database/HiveDatabaseMetaData.java
b/database/connector/dialect/hive/src/main/java/org/apache/shardingsphere/database/connector/hive/metadata/database/HiveDatabaseMetaData.java
index f7f8ec01582..95ee52365eb 100644
---
a/database/connector/dialect/hive/src/main/java/org/apache/shardingsphere/database/connector/hive/metadata/database/HiveDatabaseMetaData.java
+++
b/database/connector/dialect/hive/src/main/java/org/apache/shardingsphere/database/connector/hive/metadata/database/HiveDatabaseMetaData.java
@@ -40,7 +40,7 @@ public final class HiveDatabaseMetaData implements
DialectDatabaseMetaData {
@Override
public IdentifierPatternType getIdentifierPatternType() {
- return IdentifierPatternType.KEEP_ORIGIN;
+ return IdentifierPatternType.LOWER_CASE;
}
@Override
diff --git
a/database/connector/dialect/hive/src/main/java/org/apache/shardingsphere/database/connector/hive/metadata/identifier/HiveIdentifierCasePolicyProvider.java
b/database/connector/dialect/hive/src/main/java/org/apache/shardingsphere/database/connector/hive/metadata/identifier/HiveIdentifierCasePolicyProvider.java
new file mode 100644
index 00000000000..d19cbfb4f9b
--- /dev/null
+++
b/database/connector/dialect/hive/src/main/java/org/apache/shardingsphere/database/connector/hive/metadata/identifier/HiveIdentifierCasePolicyProvider.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.shardingsphere.database.connector.hive.metadata.identifier;
+
+import
org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierCasePolicyFactory;
+import
org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierCasePolicyProvider;
+import
org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierCasePolicyProviderContext;
+import
org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierCasePolicySet;
+
+/**
+ * Hive provider of identifier case policies.
+ */
+public final class HiveIdentifierCasePolicyProvider implements
IdentifierCasePolicyProvider {
+
+ @Override
+ public IdentifierCasePolicySet provide(final
IdentifierCasePolicyProviderContext context) {
+ return IdentifierCasePolicyFactory.newLowerCaseInsensitivePolicySet();
+ }
+
+ @Override
+ public String getDatabaseType() {
+ return "Hive";
+ }
+}
diff --git
a/database/connector/dialect/hive/src/main/resources/META-INF/services/org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierCasePolicyProvider
b/database/connector/dialect/hive/src/main/resources/META-INF/services/org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierCasePolicyProvider
new file mode 100644
index 00000000000..eb96536bf3d
--- /dev/null
+++
b/database/connector/dialect/hive/src/main/resources/META-INF/services/org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierCasePolicyProvider
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.database.connector.hive.metadata.identifier.HiveIdentifierCasePolicyProvider
diff --git
a/database/connector/dialect/hive/src/test/java/org/apache/shardingsphere/database/connector/hive/metadata/database/HiveDatabaseMetaDataTest.java
b/database/connector/dialect/hive/src/test/java/org/apache/shardingsphere/database/connector/hive/metadata/database/HiveDatabaseMetaDataTest.java
index 8f86e4fada0..c4d993797d4 100644
---
a/database/connector/dialect/hive/src/test/java/org/apache/shardingsphere/database/connector/hive/metadata/database/HiveDatabaseMetaDataTest.java
+++
b/database/connector/dialect/hive/src/test/java/org/apache/shardingsphere/database/connector/hive/metadata/database/HiveDatabaseMetaDataTest.java
@@ -52,7 +52,7 @@ class HiveDatabaseMetaDataTest {
@Test
void assertGetIdentifierPatternType() {
- assertThat(dialectDatabaseMetaData.getIdentifierPatternType(),
is(IdentifierPatternType.KEEP_ORIGIN));
+ assertThat(dialectDatabaseMetaData.getIdentifierPatternType(),
is(IdentifierPatternType.LOWER_CASE));
}
@Test
diff --git
a/database/connector/dialect/hive/src/test/java/org/apache/shardingsphere/database/connector/hive/metadata/identifier/HiveIdentifierCasePolicyProviderTest.java
b/database/connector/dialect/hive/src/test/java/org/apache/shardingsphere/database/connector/hive/metadata/identifier/HiveIdentifierCasePolicyProviderTest.java
new file mode 100644
index 00000000000..fc17b47c357
--- /dev/null
+++
b/database/connector/dialect/hive/src/test/java/org/apache/shardingsphere/database/connector/hive/metadata/identifier/HiveIdentifierCasePolicyProviderTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.shardingsphere.database.connector.hive.metadata.identifier;
+
+import
org.apache.shardingsphere.database.connector.core.metadata.database.enums.QuoteCharacter;
+import
org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierCasePolicy;
+import
org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierCasePolicyProvider;
+import
org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierCasePolicyProviderContext;
+import
org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierScope;
+import
org.apache.shardingsphere.database.connector.core.metadata.identifier.LookupMode;
+import
org.apache.shardingsphere.database.connector.core.spi.DatabaseTypedSPILoader;
+import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.isA;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class HiveIdentifierCasePolicyProviderTest {
+
+ private final DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "Hive");
+
+ private final IdentifierCasePolicyProvider provider =
DatabaseTypedSPILoader.getService(IdentifierCasePolicyProvider.class,
databaseType);
+
+ @Test
+ void assertGetDatabaseType() {
+ assertThat(provider, isA(HiveIdentifierCasePolicyProvider.class));
+ assertThat(provider.getDatabaseType(), is("Hive"));
+ }
+
+ @Test
+ void assertProvide() {
+ IdentifierCasePolicy actual = provider.provide(new
IdentifierCasePolicyProviderContext(databaseType,
null)).getPolicy(IdentifierScope.TABLE);
+ assertThat(actual.getLookupMode(QuoteCharacter.NONE),
is(LookupMode.NORMALIZED));
+ assertThat(actual.getLookupMode(QuoteCharacter.BACK_QUOTE),
is(LookupMode.NORMALIZED));
+ assertThat(actual.normalizeForDefinition("FooTable",
QuoteCharacter.NONE), is("footable"));
+ assertThat(actual.normalizeForDefinition("FooTable",
QuoteCharacter.BACK_QUOTE), is("footable"));
+ assertTrue(actual.matches("foo_table", "FOO_TABLE",
QuoteCharacter.NONE));
+ assertTrue(actual.matches("foo_table", "FOO_TABLE",
QuoteCharacter.BACK_QUOTE));
+ }
+}