You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2026/09/28 03:19:38 UTC

(shardingsphere) branch master updated: Replace deprecated identifier formatting in SQL E2E tests (#39985)

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 cfb1e564039 Replace deprecated identifier formatting in SQL E2E tests (#39985)
cfb1e564039 is described below

commit cfb1e564039ce9a2b08672090a5b1a08ceb7914a
Author: Haoran Meng <me...@gmail.com>
AuthorDate: Mon Sep 28 11:19:30 2026 +0800

    Replace deprecated identifier formatting in SQL E2E tests (#39985)
---
 .../e2e/sql/env/DataSetEnvironmentManager.java     | 17 +++++++---
 .../test/e2e/sql/it/sql/ddl/DDLE2EIT.java          | 39 ++++++++++++++++------
 2 files changed, 41 insertions(+), 15 deletions(-)

diff --git a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/sql/env/DataSetEnvironmentManager.java b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/sql/env/DataSetEnvironmentManager.java
index 2f4f641574f..f56ec3858ea 100644
--- a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/sql/env/DataSetEnvironmentManager.java
+++ b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/sql/env/DataSetEnvironmentManager.java
@@ -22,6 +22,9 @@ import lombok.Getter;
 import lombok.RequiredArgsConstructor;
 import lombok.SneakyThrows;
 import org.apache.shardingsphere.database.connector.core.metadata.database.metadata.option.sqlbatch.DialectSQLBatchOption;
+import org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierCasePolicy;
+import org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierNormalizeEngine;
+import org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierScope;
 import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
 import org.apache.shardingsphere.database.connector.core.type.DatabaseTypeFactory;
 import org.apache.shardingsphere.database.connector.core.type.DatabaseTypeRegistry;
@@ -46,6 +49,7 @@ import java.sql.PreparedStatement;
 import java.sql.SQLException;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.LinkedList;
@@ -78,6 +82,8 @@ public final class DataSetEnvironmentManager {
     
     private static final Map<String, String> TRUNCATE_SQL_CACHE = new ConcurrentHashMap<>();
     
+    private final Map<DataSource, IdentifierCasePolicy> tableIdentifierPolicies = new HashMap<>();
+    
     private final String dataSetFile;
     
     private final DataSet dataSet;
@@ -193,12 +199,15 @@ public final class DataSetEnvironmentManager {
     private List<Callable<Void>> createDeleteTasks(final ResetPlan resetPlan) throws SQLException {
         List<Callable<Void>> result = new LinkedList<>();
         for (Entry<String, Collection<String>> entry : resetPlan.getTableNamesByDataSourceName().entrySet()) {
-            DatabaseType databaseType = getDatabaseType(entry.getKey(), dataSourceMap.get(entry.getKey()));
+            DataSource dataSource = dataSourceMap.get(entry.getKey());
+            DatabaseType databaseType = getDatabaseType(entry.getKey(), dataSource);
+            IdentifierCasePolicy tableIdentifierPolicy = tableIdentifierPolicies.computeIfAbsent(dataSource,
+                    unused -> IdentifierNormalizeEngine.resolvePolicy(databaseType, dataSource, IdentifierScope.TABLE));
             Collection<String> truncateSQLs = new LinkedList<>();
             for (String each : entry.getValue()) {
-                truncateSQLs.add(getTruncateSQL(each, databaseType));
+                truncateSQLs.add(getTruncateSQL(IdentifierNormalizeEngine.normalize(tableIdentifierPolicy, each), databaseType));
             }
-            result.add(new DeleteTask(dataSourceMap.get(entry.getKey()), truncateSQLs));
+            result.add(new DeleteTask(dataSource, truncateSQLs));
         }
         return result;
     }
@@ -209,7 +218,7 @@ public final class DataSetEnvironmentManager {
     
     private static String getQuotedTableName(final String tableName, final DatabaseType databaseType) {
         DatabaseTypeRegistry databaseTypeRegistry = new DatabaseTypeRegistry(databaseType);
-        return databaseTypeRegistry.getDialectDatabaseMetaData().getQuoteCharacter().wrap(databaseTypeRegistry.formatIdentifierPattern(tableName));
+        return databaseTypeRegistry.getDialectDatabaseMetaData().getQuoteCharacter().wrap(tableName);
     }
     
     private ResetPlan getResetPlan(final Collection<String> tableNames) {
diff --git a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/sql/it/sql/ddl/DDLE2EIT.java b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/sql/it/sql/ddl/DDLE2EIT.java
index b94d82e2aa7..4abca18e3bc 100644
--- a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/sql/it/sql/ddl/DDLE2EIT.java
+++ b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/sql/it/sql/ddl/DDLE2EIT.java
@@ -19,8 +19,10 @@ package org.apache.shardingsphere.test.e2e.sql.it.sql.ddl;
 
 import com.google.common.base.Splitter;
 import lombok.Setter;
+import org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierCasePolicy;
+import org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierNormalizeEngine;
+import org.apache.shardingsphere.database.connector.core.metadata.identifier.IdentifierScope;
 import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
-import org.apache.shardingsphere.database.connector.core.type.DatabaseTypeRegistry;
 import org.apache.shardingsphere.infra.datanode.DataNode;
 import org.apache.shardingsphere.infra.expr.entry.InlineExpressionParserFactory;
 import org.apache.shardingsphere.test.e2e.env.runtime.E2ETestEnvironment;
@@ -40,6 +42,7 @@ import org.junit.jupiter.api.condition.EnabledIf;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.ArgumentsSource;
 
+import javax.sql.DataSource;
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
 import java.sql.PreparedStatement;
@@ -48,9 +51,11 @@ import java.sql.SQLException;
 import java.sql.Statement;
 import java.time.Duration;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
@@ -81,6 +86,8 @@ class DDLE2EIT implements SQLE2EIT {
     
     private static final Pattern DROP_INDEX_PATTERN = Pattern.compile("(?is)^\\s*DROP\\s+INDEX\\s+([^\\s(]+).*");
     
+    private final Map<DataSource, IdentifierCasePolicy> tableIdentifierPolicies = new HashMap<>();
+    
     private SQLE2EEnvironmentEngine environmentEngine;
     
     @ParameterizedTest(name = "{0}", allowZeroInvocations = true)
@@ -223,8 +230,10 @@ class DDLE2EIT implements SQLE2EIT {
         }
         boolean tableExists = false;
         for (DataNode each : dataNodes) {
-            try (Connection connection = environmentEngine.getActualDataSourceMap().get(each.getDataSourceName()).getConnection()) {
-                if (containsTable(connection, each.getTableName(), databaseType)) {
+            DataSource dataSource = environmentEngine.getActualDataSourceMap().get(each.getDataSourceName());
+            IdentifierCasePolicy tableIdentifierPolicy = getTableIdentifierPolicy(databaseType, dataSource);
+            try (Connection connection = dataSource.getConnection()) {
+                if (containsTable(connection, each.getTableName(), tableIdentifierPolicy)) {
                     tableExists = true;
                     break;
                 }
@@ -233,6 +242,10 @@ class DDLE2EIT implements SQLE2EIT {
         assertTrue(tableExists, "Expected table does not exist");
     }
     
+    private IdentifierCasePolicy getTableIdentifierPolicy(final DatabaseType databaseType, final DataSource dataSource) {
+        return tableIdentifierPolicies.computeIfAbsent(dataSource, unused -> IdentifierNormalizeEngine.resolvePolicy(databaseType, dataSource, IdentifierScope.TABLE));
+    }
+    
     private boolean waitIndexExists(final SQLE2EITContext context, final String tableName, final String indexName, final boolean exists) {
         Collection<DataNode> dataNodes = findDataNodes(context, getIdentifierValue(tableName));
         if (dataNodes.isEmpty()) {
@@ -303,18 +316,20 @@ class DDLE2EIT implements SQLE2EIT {
     
     private void assertNotContainsTable(final SQLE2EEnvironmentEngine environmentEngine, final Collection<DataNode> dataNodes, final DatabaseType databaseType) throws SQLException {
         for (DataNode each : dataNodes) {
-            try (Connection connection = environmentEngine.getActualDataSourceMap().get(each.getDataSourceName()).getConnection()) {
-                assertNotContainsTable(connection, each.getTableName(), databaseType);
+            DataSource dataSource = environmentEngine.getActualDataSourceMap().get(each.getDataSourceName());
+            IdentifierCasePolicy tableIdentifierPolicy = getTableIdentifierPolicy(databaseType, dataSource);
+            try (Connection connection = dataSource.getConnection()) {
+                assertNotContainsTable(connection, each.getTableName(), tableIdentifierPolicy);
             }
         }
     }
     
-    private void assertNotContainsTable(final Connection connection, final String tableName, final DatabaseType databaseType) throws SQLException {
-        assertFalse(containsTable(connection, tableName, databaseType), String.format("Table `%s` should not existed", tableName));
+    private void assertNotContainsTable(final Connection connection, final String tableName, final IdentifierCasePolicy tableIdentifierPolicy) throws SQLException {
+        assertFalse(containsTable(connection, tableName, tableIdentifierPolicy), String.format("Table `%s` should not existed", tableName));
     }
     
-    private boolean containsTable(final Connection connection, final String tableName, final DatabaseType databaseType) throws SQLException {
-        try (ResultSet resultSet = connection.getMetaData().getTables(null, null, new DatabaseTypeRegistry(databaseType).formatIdentifierPattern(tableName), new String[]{"TABLE", "VIEW"})) {
+    private boolean containsTable(final Connection connection, final String tableName, final IdentifierCasePolicy tableIdentifierPolicy) throws SQLException {
+        try (ResultSet resultSet = connection.getMetaData().getTables(null, null, IdentifierNormalizeEngine.normalize(tableIdentifierPolicy, tableName), new String[]{"TABLE", "VIEW"})) {
             return resultSet.next();
         }
     }
@@ -323,8 +338,10 @@ class DDLE2EIT implements SQLE2EIT {
     private List<DataSetColumn> getActualColumns(final Collection<DataNode> dataNodes, final DatabaseType databaseType) throws SQLException {
         Collection<DataSetColumn> result = new LinkedHashSet<>();
         for (DataNode each : dataNodes) {
-            try (Connection connection = environmentEngine.getActualDataSourceMap().get(each.getDataSourceName()).getConnection()) {
-                result.addAll(getActualColumns(connection, new DatabaseTypeRegistry(databaseType).formatIdentifierPattern(each.getTableName())));
+            DataSource dataSource = environmentEngine.getActualDataSourceMap().get(each.getDataSourceName());
+            IdentifierCasePolicy tableIdentifierPolicy = getTableIdentifierPolicy(databaseType, dataSource);
+            try (Connection connection = dataSource.getConnection()) {
+                result.addAll(getActualColumns(connection, IdentifierNormalizeEngine.normalize(tableIdentifierPolicy, each.getTableName())));
             }
         }
         return new LinkedList<>(result);