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/03/26 02:19:04 UTC

(shardingsphere) branch master updated: Remove the to lower case for YamlTableSwapper (#38554)

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

menghaoran 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 3288a9755ba Remove the to lower case for YamlTableSwapper (#38554)
3288a9755ba is described below

commit 3288a9755bafa6b88fcaa8a000395643f6842222
Author: Haoran Meng <me...@gmail.com>
AuthorDate: Thu Mar 26 10:18:57 2026 +0800

    Remove the to lower case for YamlTableSwapper (#38554)
---
 .../yaml/schema/swapper/YamlTableSwapper.java      |  6 +-
 .../yaml/schema/swapper/YamlTableSwapperTest.java  | 92 ++++++++++++++++++++++
 .../src/test/resources/yaml/schema/table.yaml      |  2 +-
 3 files changed, 96 insertions(+), 4 deletions(-)

diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlTableSwapper.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlTableSwapper.java
index 25211c8aabc..8f24714d846 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlTableSwapper.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlTableSwapper.java
@@ -56,15 +56,15 @@ public final class YamlTableSwapper implements YamlConfigurationSwapper<YamlShar
     }
     
     private Map<String, YamlShardingSphereColumn> swapToYamlColumns(final Collection<ShardingSphereColumn> columns) {
-        return columns.stream().collect(Collectors.toMap(key -> key.getName().toLowerCase(), columnSwapper::swapToYamlConfiguration, (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
+        return columns.stream().collect(Collectors.toMap(ShardingSphereColumn::getName, columnSwapper::swapToYamlConfiguration, (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
     }
     
     private Map<String, YamlShardingSphereIndex> swapToYamlIndexes(final Collection<ShardingSphereIndex> indexes) {
-        return indexes.stream().collect(Collectors.toMap(key -> key.getName().toLowerCase(), indexSwapper::swapToYamlConfiguration, (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
+        return indexes.stream().collect(Collectors.toMap(ShardingSphereIndex::getName, indexSwapper::swapToYamlConfiguration, (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
     }
     
     private Map<String, YamlShardingSphereConstraint> swapToYamlConstraints(final Collection<ShardingSphereConstraint> constrains) {
-        return constrains.stream().collect(Collectors.toMap(key -> key.getName().toLowerCase(), constraintSwapper::swapToYamlConfiguration, (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
+        return constrains.stream().collect(Collectors.toMap(ShardingSphereConstraint::getName, constraintSwapper::swapToYamlConfiguration, (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
     }
     
     @Override
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlTableSwapperTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlTableSwapperTest.java
index 60b769953a2..f15d071e544 100644
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlTableSwapperTest.java
+++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlTableSwapperTest.java
@@ -24,13 +24,22 @@ import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSp
 import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
 import org.apache.shardingsphere.infra.util.file.SystemResourceFileUtils;
 import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
+import org.apache.shardingsphere.infra.yaml.schema.pojo.YamlShardingSphereColumn;
+import org.apache.shardingsphere.infra.yaml.schema.pojo.YamlShardingSphereConstraint;
+import org.apache.shardingsphere.infra.yaml.schema.pojo.YamlShardingSphereIndex;
 import org.apache.shardingsphere.infra.yaml.schema.pojo.YamlShardingSphereTable;
 import org.junit.jupiter.api.Test;
 
+import java.util.Arrays;
+import java.util.LinkedHashMap;
 import java.util.Collections;
+import java.util.Map;
 
 import static org.apache.shardingsphere.test.infra.framework.matcher.ShardingSphereAssertionMatchers.deepEqual;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasKey;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
 
 class YamlTableSwapperTest {
     
@@ -62,10 +71,93 @@ class YamlTableSwapperTest {
         assertThat(actual, deepEqual(expected));
     }
     
+    @Test
+    void assertSwapToYamlConfigurationWithCaseSensitiveKeys() {
+        ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
+                Arrays.asList(new ShardingSphereColumn("Foo_Col", 0, true, false, false, true, false, false),
+                        new ShardingSphereColumn("foo_col", 1, false, false, false, true, false, false)),
+                Arrays.asList(new ShardingSphereIndex("Foo_Idx", Collections.emptyList(), false), new ShardingSphereIndex("foo_idx", Collections.emptyList(), false)),
+                Arrays.asList(new ShardingSphereConstraint("Foo_Constraint", "foo_tbl"), new ShardingSphereConstraint("foo_constraint", "foo_tbl")), TableType.TABLE);
+        YamlShardingSphereTable actual = swapper.swapToYamlConfiguration(table);
+        assertThat(actual.getColumns().size(), is(2));
+        assertThat(actual.getColumns(), hasKey("Foo_Col"));
+        assertThat(actual.getColumns(), hasKey("foo_col"));
+        assertThat(actual.getIndexes().size(), is(2));
+        assertThat(actual.getIndexes(), hasKey("Foo_Idx"));
+        assertThat(actual.getIndexes(), hasKey("foo_idx"));
+        assertThat(actual.getConstraints().size(), is(2));
+        assertThat(actual.getConstraints(), hasKey("Foo_Constraint"));
+        assertThat(actual.getConstraints(), hasKey("foo_constraint"));
+        assertThat(actual.getColumns(), not(hasKey("FOO_COL")));
+    }
+    
+    @Test
+    void assertSwapToObjectWithCaseSensitiveYamlKeys() {
+        YamlShardingSphereTable yamlTable = new YamlShardingSphereTable();
+        yamlTable.setName("foo_tbl");
+        yamlTable.setColumns(createYamlColumns());
+        yamlTable.setIndexes(createYamlIndexes());
+        yamlTable.setConstraints(createYamlConstraints());
+        yamlTable.setType(TableType.TABLE);
+        ShardingSphereTable actual = swapper.swapToObject(yamlTable);
+        assertThat(actual.getAllColumns().size(), is(2));
+        assertThat(actual.getAllIndexes().size(), is(2));
+        assertThat(actual.getAllConstraints().size(), is(2));
+    }
+    
     private ShardingSphereTable createShardingSphereTable() {
         return new ShardingSphereTable("foo_tbl",
                 Collections.singleton(new ShardingSphereColumn("foo_col", 0, true, false, false, true, false, false)),
                 Collections.singleton(new ShardingSphereIndex("PRIMARY", Collections.emptyList(), false)),
                 Collections.singleton(new ShardingSphereConstraint("foo_constraint", "foo_tbl")), null);
     }
+    
+    private Map<String, YamlShardingSphereColumn> createYamlColumns() {
+        Map<String, YamlShardingSphereColumn> result = new LinkedHashMap<>(2, 1F);
+        result.put("Foo_Col", createYamlColumn("Foo_Col", 0, true));
+        result.put("foo_col", createYamlColumn("foo_col", 1, false));
+        return result;
+    }
+    
+    private YamlShardingSphereColumn createYamlColumn(final String name, final int dataType, final boolean primaryKey) {
+        YamlShardingSphereColumn result = new YamlShardingSphereColumn();
+        result.setName(name);
+        result.setDataType(dataType);
+        result.setPrimaryKey(primaryKey);
+        result.setGenerated(false);
+        result.setCaseSensitive(false);
+        result.setVisible(true);
+        result.setUnsigned(false);
+        result.setNullable(false);
+        return result;
+    }
+    
+    private Map<String, YamlShardingSphereIndex> createYamlIndexes() {
+        Map<String, YamlShardingSphereIndex> result = new LinkedHashMap<>(2, 1F);
+        result.put("Foo_Idx", createYamlIndex("Foo_Idx"));
+        result.put("foo_idx", createYamlIndex("foo_idx"));
+        return result;
+    }
+    
+    private YamlShardingSphereIndex createYamlIndex(final String name) {
+        YamlShardingSphereIndex result = new YamlShardingSphereIndex();
+        result.setName(name);
+        result.setColumns(Collections.emptyList());
+        result.setUnique(false);
+        return result;
+    }
+    
+    private Map<String, YamlShardingSphereConstraint> createYamlConstraints() {
+        Map<String, YamlShardingSphereConstraint> result = new LinkedHashMap<>(2, 1F);
+        result.put("Foo_Constraint", createYamlConstraint("Foo_Constraint"));
+        result.put("foo_constraint", createYamlConstraint("foo_constraint"));
+        return result;
+    }
+    
+    private YamlShardingSphereConstraint createYamlConstraint(final String name) {
+        YamlShardingSphereConstraint result = new YamlShardingSphereConstraint();
+        result.setName(name);
+        result.setReferencedTableName("foo_tbl");
+        return result;
+    }
 }
diff --git a/infra/common/src/test/resources/yaml/schema/table.yaml b/infra/common/src/test/resources/yaml/schema/table.yaml
index adb4a9a552c..cf7269e5149 100644
--- a/infra/common/src/test/resources/yaml/schema/table.yaml
+++ b/infra/common/src/test/resources/yaml/schema/table.yaml
@@ -27,7 +27,7 @@ columns:
     unsigned: false
     nullable: false
 indexes:
-   primary:
+   PRIMARY:
       name: PRIMARY
 constraints:
   foo_constraint: