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

(shardingsphere) branch master updated: Canonicalize quoted CDC table selectors (#39715)

This is an automated email from the ASF dual-hosted git repository.

terrymanu 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 44d5e69d1d2 Canonicalize quoted CDC table selectors (#39715)
44d5e69d1d2 is described below

commit 44d5e69d1d2e52395df4f49732e2b1d49b820636
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Thu Sep 3 20:55:05 2026 +0800

    Canonicalize quoted CDC table selectors (#39715)
---
 .../pipeline/cdc/util/CDCSchemaTableUtils.java     | 17 ++++++++++++----
 .../pipeline/cdc/util/CDCSchemaTableUtilsTest.java | 23 ++++++++++++++++++++++
 2 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCSchemaTableUtils.java b/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCSchemaTableUtils.java
index 771985bfb70..d6486692d91 100644
--- a/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCSchemaTableUtils.java
+++ b/kernel/data-pipeline/scenario/cdc/core/src/main/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCSchemaTableUtils.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.data.pipeline.cdc.util;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.data.pipeline.cdc.protocol.request.StreamDataRequestBody.SchemaTable;
+import org.apache.shardingsphere.database.connector.core.metadata.database.enums.QuoteCharacter;
 import org.apache.shardingsphere.database.connector.core.metadata.database.metadata.DialectDatabaseMetaData;
 import org.apache.shardingsphere.database.connector.core.metadata.database.system.DialectSystemDatabase;
 import org.apache.shardingsphere.database.connector.core.spi.DatabaseTypedSPILoader;
@@ -76,8 +77,11 @@ public final class CDCSchemaTableUtils {
                 String schemaName = each.getSchema().isEmpty() ? dialectDatabaseMetaData.getSchemaOption().getDefaultSchema().orElse("") : each.getSchema();
                 ShardingSphereSchema schema = database.getSchema(new IdentifierValue(schemaName));
                 ShardingSpherePreconditions.checkNotNull(schema, () -> new SchemaNotFoundException(schemaName));
-                ShardingSpherePreconditions.checkNotNull(schema.getTable(each.getTable()), () -> new TableNotFoundException(each.getTable()));
-                result.computeIfAbsent(schema.getName(), ignored -> new HashSet<>()).add(each.getTable());
+                IdentifierValue tableName = new IdentifierValue(each.getTable());
+                ShardingSphereTable matchedTable = schema.getTable(tableName);
+                ShardingSpherePreconditions.checkNotNull(matchedTable, () -> new TableNotFoundException(each.getTable()));
+                result.computeIfAbsent(schema.getName(), ignored -> new HashSet<>())
+                        .add(QuoteCharacter.NONE == tableName.getQuoteCharacter() ? each.getTable() : matchedTable.getName());
             }
         }
         return result;
@@ -99,10 +103,15 @@ public final class CDCSchemaTableUtils {
     
     private static Map<String, Set<String>> parseTableExpressionWithAllSchema(final ShardingSphereDatabase database, final Collection<String> systemSchemas, final SchemaTable table) {
         Map<String, Set<String>> result = new HashMap<>(database.getAllSchemas().size(), 1F);
+        IdentifierValue tableName = new IdentifierValue(table.getTable());
         for (ShardingSphereSchema schema : database.getAllSchemas()) {
             if (!systemSchemas.contains(schema.getName())) {
-                schema.getAllTables().stream().filter(each -> each.getName().equals(table.getTable())).findFirst()
-                        .ifPresent(optional -> result.computeIfAbsent(schema.getName(), ignored -> new HashSet<>()).add(optional.getName()));
+                ShardingSphereTable matchedTable = QuoteCharacter.NONE == tableName.getQuoteCharacter()
+                        ? schema.getAllTables().stream().filter(each -> each.getName().equals(table.getTable())).findFirst().orElse(null)
+                        : schema.getTable(tableName);
+                if (null != matchedTable) {
+                    result.computeIfAbsent(schema.getName(), ignored -> new HashSet<>()).add(matchedTable.getName());
+                }
             }
         }
         return result;
diff --git a/kernel/data-pipeline/scenario/cdc/core/src/test/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCSchemaTableUtilsTest.java b/kernel/data-pipeline/scenario/cdc/core/src/test/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCSchemaTableUtilsTest.java
index 995b68eb145..b0e57728757 100644
--- a/kernel/data-pipeline/scenario/cdc/core/src/test/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCSchemaTableUtilsTest.java
+++ b/kernel/data-pipeline/scenario/cdc/core/src/test/java/org/apache/shardingsphere/data/pipeline/cdc/util/CDCSchemaTableUtilsTest.java
@@ -92,6 +92,18 @@ class CDCSchemaTableUtilsTest {
         assertThat(actualResult, is(expectedResult));
     }
     
+    @Test
+    void assertParseTableExpressionsWithSchemaWildcardAndQuotedTable() {
+        ShardingSphereSchema fooSchema = mockSchema("foo_schema", "footable", "FooTable");
+        ShardingSphereSchema barSchema = mockSchema("bar_schema", "footable");
+        ShardingSphereDatabase database =
+                new ShardingSphereDatabase("sharding_db", databaseType, null, null, Arrays.asList(fooSchema, barSchema), new ConfigurationProperties(new Properties()));
+        List<SchemaTable> schemaTables = Collections.singletonList(SchemaTable.newBuilder().setSchema("*").setTable("\"FooTable\"").build());
+        Map<String, Set<String>> actualResult = CDCSchemaTableUtils.parseTableExpressions(database, schemaTables);
+        Map<String, Set<String>> expectedResult = Collections.singletonMap("foo_schema", Collections.singleton("FooTable"));
+        assertThat(actualResult, is(expectedResult));
+    }
+    
     @Test
     void assertParseTableExpressionsMergesSchemaWildcardResults() {
         ShardingSphereSchema publicSchema = mockSchema("public", "t_order", "t_order_item");
@@ -151,6 +163,17 @@ class CDCSchemaTableUtilsTest {
         assertThat(actualResult, is(expectedResult));
     }
     
+    @Test
+    void assertParseTableExpressionsWithQuotedTable() {
+        ShardingSphereSchema schema = mockSchema("foo_schema", "footable", "FooTable");
+        ShardingSphereDatabase database =
+                new ShardingSphereDatabase("sharding_db", databaseType, null, null, Collections.singleton(schema), new ConfigurationProperties(new Properties()));
+        List<SchemaTable> schemaTables = Collections.singletonList(SchemaTable.newBuilder().setSchema("foo_schema").setTable("\"FooTable\"").build());
+        Map<String, Set<String>> actualResult = CDCSchemaTableUtils.parseTableExpressions(database, schemaTables);
+        Map<String, Set<String>> expectedResult = Collections.singletonMap("foo_schema", Collections.singleton("FooTable"));
+        assertThat(actualResult, is(expectedResult));
+    }
+    
     @Test
     void assertParseTableExpressionsFillDefaultSchema() {
         ShardingSphereSchema publicSchema = mockSchema("public", "t_order");