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

chengzhang 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 5eb48b1cdcd Refactor RepositoryTupleSwapper.swapToObject0() (#31074)
5eb48b1cdcd is described below

commit 5eb48b1cdcdcd70c735bf4d90bf1fc2075794b09
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Apr 30 18:01:06 2024 +0800

    Refactor RepositoryTupleSwapper.swapToObject0() (#31074)
    
    * Refactor RepositoryTupleSwapper.swapToObject0()
    
    * Refactor RepositoryTupleSwapper.swapToObject0()
---
 ...astRuleConfigurationRepositoryTupleSwapper.java | 11 +++++
 ...uleConfigurationRepositoryTupleSwapperTest.java |  4 +-
 ...yptRuleConfigurationRepositoryTupleSwapper.java | 20 +++++++++
 ...uleConfigurationRepositoryTupleSwapperTest.java | 14 +++----
 ...askRuleConfigurationRepositoryTupleSwapper.java | 20 +++++++++
 ...uleConfigurationRepositoryTupleSwapperTest.java | 12 +++---
 ...ingRuleConfigurationRepositoryTupleSwapper.java | 20 +++++++++
 ...uleConfigurationRepositoryTupleSwapperTest.java | 14 +++----
 ...dowRuleConfigurationRepositoryTupleSwapper.java | 27 ++++++++++++
 ...uleConfigurationRepositoryTupleSwapperTest.java | 10 ++---
 ...ingRuleConfigurationRepositoryTupleSwapper.java | 48 ++++++++++++++++++++++
 ...uleConfigurationRepositoryTupleSwapperTest.java |  8 ++--
 .../rule/YamlRuleConfigurationSwapperEngine.java   | 13 ++++++
 ...ityRuleConfigurationRepositoryTupleSwapper.java | 10 +++++
 ...ockRuleConfigurationRepositoryTupleSwapper.java | 10 +++++
 ...ingRuleConfigurationRepositoryTupleSwapper.java | 10 +++++
 .../config/RepositoryTupleSwapperEngine.java       |  9 +++-
 ...gleRuleConfigurationRepositoryTupleSwapper.java | 10 +++++
 ...ionRuleConfigurationRepositoryTupleSwapper.java | 10 +++++
 ...serRuleConfigurationRepositoryTupleSwapper.java | 10 +++++
 ...torRuleConfigurationRepositoryTupleSwapper.java | 10 +++++
 ...ficRuleConfigurationRepositoryTupleSwapper.java | 10 +++++
 ...ionRuleConfigurationRepositoryTupleSwapper.java | 10 +++++
 .../mode/spi/RepositoryTupleSwapper.java           |  8 ++++
 24 files changed, 295 insertions(+), 33 deletions(-)

diff --git 
a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/yaml/swapper/BroadcastRuleConfigurationRepositoryTupleSwapper.java
 
b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/yaml/swapper/BroadcastRuleConfigurationRepositoryTupleSwapper.java
index b57b52066de..cd8b8d46258 100644
--- 
a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/yaml/swapper/BroadcastRuleConfigurationRepositoryTupleSwapper.java
+++ 
b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/yaml/swapper/BroadcastRuleConfigurationRepositoryTupleSwapper.java
@@ -48,6 +48,17 @@ public final class 
BroadcastRuleConfigurationRepositoryTupleSwapper implements R
                 : Collections.singleton(new 
RepositoryTuple(BroadcastRuleNodePathProvider.TABLES, 
YamlEngine.marshal(yamlRuleConfig)));
     }
     
+    @Override
+    public Optional<YamlBroadcastRuleConfiguration> swapToObject0(final 
Collection<RepositoryTuple> repositoryTuples) {
+        List<RepositoryTuple> validTuples = 
repositoryTuples.stream().filter(each -> 
broadcastRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
+        for (RepositoryTuple each : validTuples) {
+            if 
(broadcastRuleNodePath.getRoot().isValidatedPath(each.getKey())) {
+                return Optional.of(YamlEngine.unmarshal(each.getValue(), 
YamlBroadcastRuleConfiguration.class));
+            }
+        }
+        return Optional.empty();
+    }
+    
     @Override
     public Optional<BroadcastRuleConfiguration> swapToObject(final 
Collection<RepositoryTuple> repositoryTuples) {
         List<RepositoryTuple> validTuples = 
repositoryTuples.stream().filter(each -> 
broadcastRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
diff --git 
a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/swapper/BroadcastRuleConfigurationRepositoryTupleSwapperTest.java
 
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/swapper/BroadcastRuleConfigurationRepositoryTupleSwapperTest.java
index e29b140d1e1..b2664b22813 100644
--- 
a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/swapper/BroadcastRuleConfigurationRepositoryTupleSwapperTest.java
+++ 
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/yaml/swapper/BroadcastRuleConfigurationRepositoryTupleSwapperTest.java
@@ -54,13 +54,13 @@ class BroadcastRuleConfigurationRepositoryTupleSwapperTest {
     
     @Test
     void assertSwapToObjectWithEmptyTuple() {
-        assertFalse(swapper.swapToObject(Collections.emptyList()).isPresent());
+        
assertFalse(swapper.swapToObject0(Collections.emptyList()).isPresent());
     }
     
     @Test
     void assertSwapToObject() {
         RepositoryTuple repositoryTuple = new 
RepositoryTuple("/metadata/foo_db/rules/broadcast/tables", "tables:\n- 
foo_table\n- foo_table2\n");
-        Optional<BroadcastRuleConfiguration> actual = 
swapper.swapToObject(Collections.singleton(repositoryTuple));
+        Optional<YamlBroadcastRuleConfiguration> actual = 
swapper.swapToObject0(Collections.singleton(repositoryTuple));
         assertTrue(actual.isPresent());
         assertThat(actual.get().getTables().size(), is(2));
         Iterator<String> iterator = actual.get().getTables().iterator();
diff --git 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationRepositoryTupleSwapper.java
 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationRepositoryTupleSwapper.java
index 8f999b3f7b5..3cfdbddc40b 100644
--- 
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationRepositoryTupleSwapper.java
+++ 
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationRepositoryTupleSwapper.java
@@ -58,6 +58,26 @@ public final class 
EncryptRuleConfigurationRepositoryTupleSwapper implements Rep
         return result;
     }
     
+    @Override
+    public Optional<YamlEncryptRuleConfiguration> swapToObject0(final 
Collection<RepositoryTuple> repositoryTuples) {
+        List<RepositoryTuple> validTuples = 
repositoryTuples.stream().filter(each -> 
encryptRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
+        if (validTuples.isEmpty()) {
+            return Optional.empty();
+        }
+        YamlEncryptRuleConfiguration yamlRuleConfig = new 
YamlEncryptRuleConfiguration();
+        Map<String, YamlEncryptTableRuleConfiguration> tables = new 
LinkedHashMap<>();
+        Map<String, YamlAlgorithmConfiguration> encryptors = new 
LinkedHashMap<>();
+        for (RepositoryTuple each : validTuples) {
+            
encryptRuleNodePath.getNamedItem(EncryptRuleNodePathProvider.TABLES).getName(each.getKey())
+                    .ifPresent(optional -> tables.put(optional, 
YamlEngine.unmarshal(each.getValue(), 
YamlEncryptTableRuleConfiguration.class)));
+            
encryptRuleNodePath.getNamedItem(EncryptRuleNodePathProvider.ENCRYPTORS).getName(each.getKey())
+                    .ifPresent(optional -> encryptors.put(optional, 
YamlEngine.unmarshal(each.getValue(), YamlAlgorithmConfiguration.class)));
+        }
+        yamlRuleConfig.setTables(tables);
+        yamlRuleConfig.setEncryptors(encryptors);
+        return Optional.of(yamlRuleConfig);
+    }
+    
     @Override
     public Optional<EncryptRuleConfiguration> swapToObject(final 
Collection<RepositoryTuple> repositoryTuples) {
         List<RepositoryTuple> validTuples = 
repositoryTuples.stream().filter(each -> 
encryptRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
diff --git 
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationRepositoryTupleSwapperTest.java
 
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationRepositoryTupleSwapperTest.java
index 314367f55eb..995e7629247 100644
--- 
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationRepositoryTupleSwapperTest.java
+++ 
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/yaml/swapper/EncryptRuleConfigurationRepositoryTupleSwapperTest.java
@@ -66,7 +66,7 @@ class EncryptRuleConfigurationRepositoryTupleSwapperTest {
     
     @Test
     void assertSwapToObjectWithEmptyTuple() {
-        assertFalse(swapper.swapToObject(Collections.emptyList()).isPresent());
+        
assertFalse(swapper.swapToObject0(Collections.emptyList()).isPresent());
     }
     
     @Test
@@ -78,14 +78,14 @@ class EncryptRuleConfigurationRepositoryTupleSwapperTest {
                 + "      name: FIXTURE\n"
                 + "    name: foo_column\n"
                 + "name: foo\n"), new 
RepositoryTuple("/metadata/foo_db/rules/encrypt/encryptors/FOO/versions/0", 
"type: FOO\n"));
-        Optional<EncryptRuleConfiguration> actual = 
swapper.swapToObject(repositoryTuples);
+        Optional<YamlEncryptRuleConfiguration> actual = 
swapper.swapToObject0(repositoryTuples);
         assertTrue(actual.isPresent());
         assertThat(actual.get().getTables().size(), is(1));
-        assertThat(actual.get().getTables().iterator().next().getName(), 
is("foo"));
-        
assertThat(actual.get().getTables().iterator().next().getColumns().size(), 
is(1));
-        
assertThat(actual.get().getTables().iterator().next().getColumns().iterator().next().getName(),
 is("foo_column"));
-        
assertThat(actual.get().getTables().iterator().next().getColumns().iterator().next().getCipher().getName(),
 is("FIXTURE"));
-        
assertThat(actual.get().getTables().iterator().next().getColumns().iterator().next().getCipher().getEncryptorName(),
 is("FOO"));
+        
assertThat(actual.get().getTables().values().iterator().next().getName(), 
is("foo"));
+        
assertThat(actual.get().getTables().values().iterator().next().getColumns().size(),
 is(1));
+        
assertThat(actual.get().getTables().values().iterator().next().getColumns().values().iterator().next().getName(),
 is("foo_column"));
+        
assertThat(actual.get().getTables().values().iterator().next().getColumns().values().iterator().next().getCipher().getName(),
 is("FIXTURE"));
+        
assertThat(actual.get().getTables().values().iterator().next().getColumns().values().iterator().next().getCipher().getEncryptorName(),
 is("FOO"));
         assertThat(actual.get().getEncryptors().size(), is(1));
         assertThat(actual.get().getEncryptors().get("FOO").getType(), 
is("FOO"));
         
assertTrue(actual.get().getEncryptors().get("FOO").getProps().isEmpty());
diff --git 
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/yaml/swapper/MaskRuleConfigurationRepositoryTupleSwapper.java
 
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/yaml/swapper/MaskRuleConfigurationRepositoryTupleSwapper.java
index a1c12a6ca9b..81cfad8bf04 100644
--- 
a/features/mask/core/src/main/java/org/apache/shardingsphere/mask/yaml/swapper/MaskRuleConfigurationRepositoryTupleSwapper.java
+++ 
b/features/mask/core/src/main/java/org/apache/shardingsphere/mask/yaml/swapper/MaskRuleConfigurationRepositoryTupleSwapper.java
@@ -58,6 +58,26 @@ public final class 
MaskRuleConfigurationRepositoryTupleSwapper implements Reposi
         return result;
     }
     
+    @Override
+    public Optional<YamlMaskRuleConfiguration> swapToObject0(final 
Collection<RepositoryTuple> repositoryTuples) {
+        List<RepositoryTuple> validTuples = 
repositoryTuples.stream().filter(each -> 
maskRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
+        if (validTuples.isEmpty()) {
+            return Optional.empty();
+        }
+        YamlMaskRuleConfiguration yamlRuleConfig = new 
YamlMaskRuleConfiguration();
+        Map<String, YamlMaskTableRuleConfiguration> tables = new 
LinkedHashMap<>();
+        Map<String, YamlAlgorithmConfiguration> maskAlgorithms = new 
LinkedHashMap<>();
+        for (RepositoryTuple each : validTuples) {
+            
maskRuleNodePath.getNamedItem(MaskRuleNodePathProvider.TABLES).getName(each.getKey())
+                    .ifPresent(optional -> tables.put(optional, 
YamlEngine.unmarshal(each.getValue(), YamlMaskTableRuleConfiguration.class)));
+            
maskRuleNodePath.getNamedItem(MaskRuleNodePathProvider.MASK_ALGORITHMS).getName(each.getKey())
+                    .ifPresent(optional -> maskAlgorithms.put(optional, 
YamlEngine.unmarshal(each.getValue(), YamlAlgorithmConfiguration.class)));
+        }
+        yamlRuleConfig.setTables(tables);
+        yamlRuleConfig.setMaskAlgorithms(maskAlgorithms);
+        return Optional.of(yamlRuleConfig);
+    }
+    
     @Override
     public Optional<MaskRuleConfiguration> swapToObject(final 
Collection<RepositoryTuple> repositoryTuples) {
         List<RepositoryTuple> validTuples = 
repositoryTuples.stream().filter(each -> 
maskRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
diff --git 
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/yaml/swapper/MaskRuleConfigurationRepositoryTupleSwapperTest.java
 
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/yaml/swapper/MaskRuleConfigurationRepositoryTupleSwapperTest.java
index e2b81ddac2e..810af7f8337 100644
--- 
a/features/mask/core/src/test/java/org/apache/shardingsphere/mask/yaml/swapper/MaskRuleConfigurationRepositoryTupleSwapperTest.java
+++ 
b/features/mask/core/src/test/java/org/apache/shardingsphere/mask/yaml/swapper/MaskRuleConfigurationRepositoryTupleSwapperTest.java
@@ -64,7 +64,7 @@ class MaskRuleConfigurationRepositoryTupleSwapperTest {
     
     @Test
     void assertSwapToObjectWithEmptyTuple() {
-        assertFalse(new 
MaskRuleConfigurationRepositoryTupleSwapper().swapToObject(new 
LinkedList<>()).isPresent());
+        assertFalse(new 
MaskRuleConfigurationRepositoryTupleSwapper().swapToObject0(new 
LinkedList<>()).isPresent());
     }
     
     @Test
@@ -75,13 +75,13 @@ class MaskRuleConfigurationRepositoryTupleSwapperTest {
                 + "    maskAlgorithm: FIXTURE\n"
                 + "name: foo\n"),
                 new 
RepositoryTuple("/metadata/foo_db/rules/mask/mask_algorithms/FIXTURE/versions/0",
 "type: FIXTURE\n"));
-        Optional<MaskRuleConfiguration> actual = new 
MaskRuleConfigurationRepositoryTupleSwapper().swapToObject(repositoryTuples);
+        Optional<YamlMaskRuleConfiguration> actual = new 
MaskRuleConfigurationRepositoryTupleSwapper().swapToObject0(repositoryTuples);
         assertTrue(actual.isPresent());
         assertThat(actual.get().getTables().size(), is(1));
-        assertThat(actual.get().getTables().iterator().next().getName(), 
is("foo"));
-        
assertThat(actual.get().getTables().iterator().next().getColumns().size(), 
is(1));
-        
assertThat(actual.get().getTables().iterator().next().getColumns().iterator().next().getLogicColumn(),
 is("foo_column"));
-        
assertThat(actual.get().getTables().iterator().next().getColumns().iterator().next().getMaskAlgorithm(),
 is("FIXTURE"));
+        
assertThat(actual.get().getTables().values().iterator().next().getName(), 
is("foo"));
+        
assertThat(actual.get().getTables().values().iterator().next().getColumns().size(),
 is(1));
+        
assertThat(actual.get().getTables().values().iterator().next().getColumns().values().iterator().next().getLogicColumn(),
 is("foo_column"));
+        
assertThat(actual.get().getTables().values().iterator().next().getColumns().values().iterator().next().getMaskAlgorithm(),
 is("FIXTURE"));
         assertThat(actual.get().getMaskAlgorithms().size(), is(1));
         assertThat(actual.get().getMaskAlgorithms().get("FIXTURE").getType(), 
is("FIXTURE"));
         
assertTrue(actual.get().getMaskAlgorithms().get("FIXTURE").getProps().isEmpty());
diff --git 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/ReadwriteSplittingRuleConfigurationRepositoryTupleSwapper.java
 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/ReadwriteSplittingRuleConfigurationRepositoryTupleSwapper.java
index 815a9d2a3ec..8830a38736e 100644
--- 
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/ReadwriteSplittingRuleConfigurationRepositoryTupleSwapper.java
+++ 
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/ReadwriteSplittingRuleConfigurationRepositoryTupleSwapper.java
@@ -60,6 +60,26 @@ public final class 
ReadwriteSplittingRuleConfigurationRepositoryTupleSwapper imp
         return result;
     }
     
+    @Override
+    public Optional<YamlReadwriteSplittingRuleConfiguration> 
swapToObject0(final Collection<RepositoryTuple> repositoryTuples) {
+        List<RepositoryTuple> validRepositoryTuples = 
repositoryTuples.stream().filter(each -> 
readwriteSplittingRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
+        if (validRepositoryTuples.isEmpty()) {
+            return Optional.empty();
+        }
+        YamlReadwriteSplittingRuleConfiguration yamlRuleConfig = new 
YamlReadwriteSplittingRuleConfiguration();
+        Map<String, YamlReadwriteSplittingDataSourceGroupRuleConfiguration> 
dataSourceGroups = new LinkedHashMap<>();
+        Map<String, YamlAlgorithmConfiguration> loadBalancers = new 
LinkedHashMap<>();
+        for (RepositoryTuple each : validRepositoryTuples) {
+            
readwriteSplittingRuleNodePath.getNamedItem(ReadwriteSplittingRuleNodePathProvider.DATA_SOURCES).getName(each.getKey())
+                    .ifPresent(optional -> dataSourceGroups.put(optional, 
YamlEngine.unmarshal(each.getValue(), 
YamlReadwriteSplittingDataSourceGroupRuleConfiguration.class)));
+            
readwriteSplittingRuleNodePath.getNamedItem(ReadwriteSplittingRuleNodePathProvider.LOAD_BALANCERS).getName(each.getKey())
+                    .ifPresent(optional -> loadBalancers.put(optional, 
YamlEngine.unmarshal(each.getValue(), YamlAlgorithmConfiguration.class)));
+        }
+        yamlRuleConfig.setDataSourceGroups(dataSourceGroups);
+        yamlRuleConfig.setLoadBalancers(loadBalancers);
+        return Optional.of(yamlRuleConfig);
+    }
+    
     @Override
     public Optional<ReadwriteSplittingRuleConfiguration> swapToObject(final 
Collection<RepositoryTuple> repositoryTuples) {
         List<RepositoryTuple> validRepositoryTuples = 
repositoryTuples.stream().filter(each -> 
readwriteSplittingRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
diff --git 
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/ReadwriteSplittingRuleConfigurationRepositoryTupleSwapperTest.java
 
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/ReadwriteSplittingRuleConfigurationRepositoryTupleSwapperTest.java
index 7d428a2594b..0cc59a74205 100644
--- 
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/ReadwriteSplittingRuleConfigurationRepositoryTupleSwapperTest.java
+++ 
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/yaml/swapper/ReadwriteSplittingRuleConfigurationRepositoryTupleSwapperTest.java
@@ -66,7 +66,7 @@ class 
ReadwriteSplittingRuleConfigurationRepositoryTupleSwapperTest {
     
     @Test
     void assertSwapToObjectWithEmptyTuple() {
-        assertFalse(swapper.swapToObject(Collections.emptyList()).isPresent());
+        
assertFalse(swapper.swapToObject0(Collections.emptyList()).isPresent());
     }
     
     @Test
@@ -78,14 +78,14 @@ class 
ReadwriteSplittingRuleConfigurationRepositoryTupleSwapperTest {
                 + "transactionalReadQueryStrategy: DYNAMIC\n"
                 + "writeDataSourceName: write_ds\n"),
                 new 
RepositoryTuple("/metadata/foo_db/rules/readwrite_splitting/load_balancers/random/versions/0",
 "type: random\n"));
-        Optional<ReadwriteSplittingRuleConfiguration> actual = 
swapper.swapToObject(repositoryTuples);
+        Optional<YamlReadwriteSplittingRuleConfiguration> actual = 
swapper.swapToObject0(repositoryTuples);
         assertTrue(actual.isPresent());
         assertThat(actual.get().getDataSourceGroups().size(), is(1));
-        
assertThat(actual.get().getDataSourceGroups().iterator().next().getName(), 
is("foo_group"));
-        
assertThat(actual.get().getDataSourceGroups().iterator().next().getWriteDataSourceName(),
 is("write_ds"));
-        
assertThat(actual.get().getDataSourceGroups().iterator().next().getReadDataSourceNames().size(),
 is(2));
-        
assertThat(actual.get().getDataSourceGroups().iterator().next().getLoadBalancerName(),
 is("random"));
-        
assertThat(actual.get().getDataSourceGroups().iterator().next().getTransactionalReadQueryStrategy(),
 is(TransactionalReadQueryStrategy.DYNAMIC));
+        
assertThat(actual.get().getDataSourceGroups().keySet().iterator().next(), 
is("foo_group"));
+        
assertThat(actual.get().getDataSourceGroups().values().iterator().next().getWriteDataSourceName(),
 is("write_ds"));
+        
assertThat(actual.get().getDataSourceGroups().values().iterator().next().getReadDataSourceNames().size(),
 is(2));
+        
assertThat(actual.get().getDataSourceGroups().values().iterator().next().getLoadBalancerName(),
 is("random"));
+        
assertThat(actual.get().getDataSourceGroups().values().iterator().next().getTransactionalReadQueryStrategy(),
 is(TransactionalReadQueryStrategy.DYNAMIC.name()));
         assertThat(actual.get().getLoadBalancers().size(), is(1));
         assertThat(actual.get().getLoadBalancers().get("random").getType(), 
is("random"));
         
assertTrue(actual.get().getLoadBalancers().get("random").getProps().isEmpty());
diff --git 
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleConfigurationRepositoryTupleSwapper.java
 
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleConfigurationRepositoryTupleSwapper.java
index b0b894b9c9a..7e274f27819 100644
--- 
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleConfigurationRepositoryTupleSwapper.java
+++ 
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleConfigurationRepositoryTupleSwapper.java
@@ -66,6 +66,33 @@ public final class 
ShadowRuleConfigurationRepositoryTupleSwapper implements Repo
         return result;
     }
     
+    @Override
+    public Optional<YamlShadowRuleConfiguration> swapToObject0(final 
Collection<RepositoryTuple> repositoryTuples) {
+        List<RepositoryTuple> validRepositoryTuples = 
repositoryTuples.stream().filter(each -> 
shadowRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
+        if (validRepositoryTuples.isEmpty()) {
+            return Optional.empty();
+        }
+        YamlShadowRuleConfiguration yamlRuleConfig = new 
YamlShadowRuleConfiguration();
+        Map<String, YamlShadowDataSourceConfiguration> dataSources = new 
LinkedHashMap<>();
+        Map<String, YamlShadowTableConfiguration> tables = new 
LinkedHashMap<>();
+        Map<String, YamlAlgorithmConfiguration> shadowAlgorithms = new 
LinkedHashMap<>();
+        for (RepositoryTuple each : validRepositoryTuples) {
+            
shadowRuleNodePath.getNamedItem(ShadowRuleNodePathProvider.DATA_SOURCES).getName(each.getKey())
+                    .ifPresent(optional -> dataSources.put(optional, 
YamlEngine.unmarshal(each.getValue(), 
YamlShadowDataSourceConfiguration.class)));
+            
shadowRuleNodePath.getNamedItem(ShadowRuleNodePathProvider.TABLES).getName(each.getKey())
+                    .ifPresent(optional -> tables.put(optional, 
YamlEngine.unmarshal(each.getValue(), YamlShadowTableConfiguration.class)));
+            
shadowRuleNodePath.getNamedItem(ShadowRuleNodePathProvider.ALGORITHMS).getName(each.getKey())
+                    .ifPresent(optional -> shadowAlgorithms.put(optional, 
YamlEngine.unmarshal(each.getValue(), YamlAlgorithmConfiguration.class)));
+            if 
(shadowRuleNodePath.getUniqueItem(ShadowRuleNodePathProvider.DEFAULT_ALGORITHM).isValidatedPath(each.getKey()))
 {
+                yamlRuleConfig.setDefaultShadowAlgorithmName(each.getValue());
+            }
+        }
+        yamlRuleConfig.setDataSources(dataSources);
+        yamlRuleConfig.setTables(tables);
+        yamlRuleConfig.setShadowAlgorithms(shadowAlgorithms);
+        return Optional.of(yamlRuleConfig);
+    }
+    
     @Override
     public Optional<ShadowRuleConfiguration> swapToObject(final 
Collection<RepositoryTuple> repositoryTuples) {
         List<RepositoryTuple> validRepositoryTuples = 
repositoryTuples.stream().filter(each -> 
shadowRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
diff --git 
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleConfigurationRepositoryTupleSwapperTest.java
 
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleConfigurationRepositoryTupleSwapperTest.java
index 89fa7703a5c..0be89d11250 100644
--- 
a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleConfigurationRepositoryTupleSwapperTest.java
+++ 
b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/yaml/swapper/ShadowRuleConfigurationRepositoryTupleSwapperTest.java
@@ -79,7 +79,7 @@ class ShadowRuleConfigurationRepositoryTupleSwapperTest {
     
     @Test
     void assertSwapToObjectWithEmptyTuple() {
-        assertFalse(swapper.swapToObject(Collections.emptyList()).isPresent());
+        
assertFalse(swapper.swapToObject0(Collections.emptyList()).isPresent());
     }
     
     @Test
@@ -92,12 +92,12 @@ class ShadowRuleConfigurationRepositoryTupleSwapperTest {
                         + "- FIXTURE\n"),
                 new 
RepositoryTuple("/metadata/foo_db/rules/shadow/algorithms/FIXTURE/versions/0", 
"type: FIXTURE\n"),
                 new 
RepositoryTuple("/metadata/foo_db/rules/shadow/default_algorithm_name/versions/0",
 "FIXTURE"));
-        Optional<ShadowRuleConfiguration> actual = 
swapper.swapToObject(repositoryTuples);
+        Optional<YamlShadowRuleConfiguration> actual = 
swapper.swapToObject0(repositoryTuples);
         assertTrue(actual.isPresent());
         assertThat(actual.get().getDataSources().size(), is(1));
-        assertThat(actual.get().getDataSources().iterator().next().getName(), 
is("foo_db"));
-        
assertThat(actual.get().getDataSources().iterator().next().getProductionDataSourceName(),
 is("ds_0"));
-        
assertThat(actual.get().getDataSources().iterator().next().getShadowDataSourceName(),
 is("ds_1"));
+        assertThat(actual.get().getDataSources().keySet().iterator().next(), 
is("foo_db"));
+        
assertThat(actual.get().getDataSources().values().iterator().next().getProductionDataSourceName(),
 is("ds_0"));
+        
assertThat(actual.get().getDataSources().values().iterator().next().getShadowDataSourceName(),
 is("ds_1"));
         assertThat(actual.get().getTables().size(), is(1));
         
assertThat(actual.get().getTables().get("foo_table").getDataSourceNames().size(),
 is(1));
         
assertThat(actual.get().getTables().get("foo_table").getDataSourceNames().iterator().next(),
 is("ds_0"));
diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationRepositoryTupleSwapper.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationRepositoryTupleSwapper.java
index cab9de03349..32494707598 100644
--- 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationRepositoryTupleSwapper.java
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationRepositoryTupleSwapper.java
@@ -113,6 +113,54 @@ public final class 
ShardingRuleConfigurationRepositoryTupleSwapper implements Re
         return bindingGroup.contains(":") ? bindingGroup.substring(0, 
bindingGroup.indexOf(":")) : bindingGroup;
     }
     
+    @Override
+    public Optional<YamlShardingRuleConfiguration> swapToObject0(final 
Collection<RepositoryTuple> repositoryTuples) {
+        List<RepositoryTuple> validRepositoryTuples = 
repositoryTuples.stream().filter(each -> 
shardingRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
+        if (validRepositoryTuples.isEmpty()) {
+            return Optional.empty();
+        }
+        YamlShardingRuleConfiguration yamlRuleConfig = new 
YamlShardingRuleConfiguration();
+        Map<String, YamlTableRuleConfiguration> tables = new LinkedHashMap<>();
+        Map<String, YamlShardingAutoTableRuleConfiguration> autoTables = new 
LinkedHashMap<>();
+        Collection<String> bindingTables = new LinkedList<>();
+        Map<String, YamlAlgorithmConfiguration> shardingAlgorithms = new 
LinkedHashMap<>();
+        Map<String, YamlAlgorithmConfiguration> keyGenerators = new 
LinkedHashMap<>();
+        Map<String, YamlAlgorithmConfiguration> auditors = new 
LinkedHashMap<>();
+        for (RepositoryTuple each : validRepositoryTuples) {
+            
shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.TABLES).getName(each.getKey())
+                    .ifPresent(optional -> tables.put(optional, 
YamlEngine.unmarshal(each.getValue(), YamlTableRuleConfiguration.class)));
+            
shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.AUTO_TABLES).getName(each.getKey())
+                    .ifPresent(optional -> autoTables.put(optional, 
YamlEngine.unmarshal(each.getValue(), 
YamlShardingAutoTableRuleConfiguration.class)));
+            
shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.BINDING_TABLES).getName(each.getKey()).ifPresent(optional
 -> bindingTables.add(each.getValue()));
+            
shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.ALGORITHMS).getName(each.getKey())
+                    .ifPresent(optional -> shardingAlgorithms.put(optional, 
YamlEngine.unmarshal(each.getValue(), YamlAlgorithmConfiguration.class)));
+            
shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.KEY_GENERATORS).getName(each.getKey())
+                    .ifPresent(optional -> keyGenerators.put(optional, 
YamlEngine.unmarshal(each.getValue(), YamlAlgorithmConfiguration.class)));
+            
shardingRuleNodePath.getNamedItem(ShardingRuleNodePathProvider.AUDITORS).getName(each.getKey())
+                    .ifPresent(optional -> auditors.put(optional, 
YamlEngine.unmarshal(each.getValue(), YamlAlgorithmConfiguration.class)));
+            if 
(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_DATABASE_STRATEGY).isValidatedPath(each.getKey()))
 {
+                
yamlRuleConfig.setDefaultDatabaseStrategy(YamlEngine.unmarshal(each.getValue(), 
YamlShardingStrategyConfiguration.class));
+            } else if 
(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_TABLE_STRATEGY).isValidatedPath(each.getKey()))
 {
+                
yamlRuleConfig.setDefaultTableStrategy(YamlEngine.unmarshal(each.getValue(), 
YamlShardingStrategyConfiguration.class));
+            } else if 
(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_KEY_GENERATE_STRATEGY).isValidatedPath(each.getKey()))
 {
+                
yamlRuleConfig.setDefaultKeyGenerateStrategy(YamlEngine.unmarshal(each.getValue(),
 YamlKeyGenerateStrategyConfiguration.class));
+            } else if 
(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_AUDIT_STRATEGY).isValidatedPath(each.getKey()))
 {
+                
yamlRuleConfig.setDefaultAuditStrategy(YamlEngine.unmarshal(each.getValue(), 
YamlShardingAuditStrategyConfiguration.class));
+            } else if 
(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.DEFAULT_SHARDING_COLUMN).isValidatedPath(each.getKey()))
 {
+                yamlRuleConfig.setDefaultShardingColumn(each.getValue());
+            } else if 
(shardingRuleNodePath.getUniqueItem(ShardingRuleNodePathProvider.SHARDING_CACHE).isValidatedPath(each.getKey()))
 {
+                
yamlRuleConfig.setShardingCache(YamlEngine.unmarshal(each.getValue(), 
YamlShardingCacheConfiguration.class));
+            }
+        }
+        yamlRuleConfig.setTables(tables);
+        yamlRuleConfig.setAutoTables(autoTables);
+        yamlRuleConfig.setBindingTables(bindingTables);
+        yamlRuleConfig.setShardingAlgorithms(shardingAlgorithms);
+        yamlRuleConfig.setKeyGenerators(keyGenerators);
+        yamlRuleConfig.setAuditors(auditors);
+        return Optional.of(yamlRuleConfig);
+    }
+    
     @Override
     public Optional<ShardingRuleConfiguration> swapToObject(final 
Collection<RepositoryTuple> repositoryTuples) {
         List<RepositoryTuple> validRepositoryTuples = 
repositoryTuples.stream().filter(each -> 
shardingRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList());
diff --git 
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationRepositoryTupleSwapperTest.java
 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationRepositoryTupleSwapperTest.java
index 885214039b0..6dd9763601b 100644
--- 
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationRepositoryTupleSwapperTest.java
+++ 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/yaml/swapper/ShardingRuleConfigurationRepositoryTupleSwapperTest.java
@@ -115,7 +115,7 @@ class ShardingRuleConfigurationRepositoryTupleSwapperTest {
     
     @Test
     void assertSwapToObjectWithEmptyTuple() {
-        assertFalse(swapper.swapToObject(Collections.emptyList()).isPresent());
+        
assertFalse(swapper.swapToObject0(Collections.emptyList()).isPresent());
     }
     
     @Test
@@ -185,9 +185,9 @@ class ShardingRuleConfigurationRepositoryTupleSwapperTest {
         repositoryTuples.add(new 
RepositoryTuple("/metadata/foo_db/rules/sharding/key_generators/auto_increment/versions/0",
 "type: AUTO_INCREMENT.FIXTURE\n"));
         repositoryTuples.add(new 
RepositoryTuple("/metadata/foo_db/rules/sharding/auditors/audit_algorithm/versions/0",
 "type: DML_SHARDING_CONDITIONS\n"));
         repositoryTuples.add(new 
RepositoryTuple("/metadata/foo_db/rules/sharding/default_strategies/default_sharding_column/versions/0",
 "table_id"));
-        Optional<ShardingRuleConfiguration> shardingRuleConfig = 
swapper.swapToObject(repositoryTuples);
-        assertTrue(shardingRuleConfig.isPresent());
-        ShardingRuleConfiguration actual = shardingRuleConfig.get();
+        Optional<YamlShardingRuleConfiguration> yamlRuleConfig = 
swapper.swapToObject0(repositoryTuples);
+        assertTrue(yamlRuleConfig.isPresent());
+        ShardingRuleConfiguration actual = (ShardingRuleConfiguration) new 
YamlRuleConfigurationSwapperEngine().swapToRuleConfiguration(yamlRuleConfig.get());
         assertThat(actual.getTables().size(), is(2));
         assertThat(actual.getTables().iterator().next().getLogicTable(), 
is("LOGIC_TABLE"));
         assertThat(actual.getTables().iterator().next().getActualDataNodes(), 
is("ds_${0..1}.table_${0..2}"));
diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/rule/YamlRuleConfigurationSwapperEngine.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/rule/YamlRuleConfigurationSwapperEngine.java
index b63c2198e2b..0fdab50ca2d 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/rule/YamlRuleConfigurationSwapperEngine.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/config/swapper/rule/YamlRuleConfigurationSwapperEngine.java
@@ -56,6 +56,19 @@ public final class YamlRuleConfigurationSwapperEngine {
                 .map(entry -> (YamlRuleConfiguration) 
entry.getValue().swapToYamlConfiguration(entry.getKey())).collect(Collectors.toList());
     }
     
+    /**
+     * Swap from YAML rule configurations to rule configuration.
+     *
+     * @param yamlRuleConfig YAML rule configuration
+     * @return rule configuration
+     */
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    public RuleConfiguration swapToRuleConfiguration(final 
YamlRuleConfiguration yamlRuleConfig) {
+        Class<?> ruleConfigType = yamlRuleConfig.getRuleConfigurationType();
+        YamlRuleConfigurationSwapper swapper = 
OrderedSPILoader.getServicesByClass(YamlRuleConfigurationSwapper.class, 
Collections.singleton(ruleConfigType)).get(ruleConfigType);
+        return (RuleConfiguration) swapper.swapToObject(yamlRuleConfig);
+    }
+    
     /**
      * Swap from YAML rule configurations to rule configurations.
      *
diff --git 
a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/AuthorityRuleConfigurationRepositoryTupleSwapper.java
 
b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/AuthorityRuleConfigurationRepositoryTupleSwapper.java
index 71396fb7c0a..1fd7947cc53 100644
--- 
a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/AuthorityRuleConfigurationRepositoryTupleSwapper.java
+++ 
b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/AuthorityRuleConfigurationRepositoryTupleSwapper.java
@@ -41,6 +41,16 @@ public final class 
AuthorityRuleConfigurationRepositoryTupleSwapper implements R
         return Collections.singleton(new 
RepositoryTuple(getRuleTagName().toLowerCase(), 
YamlEngine.marshal(yamlRuleConfig)));
     }
     
+    @Override
+    public Optional<YamlAuthorityRuleConfiguration> swapToObject0(final 
Collection<RepositoryTuple> repositoryTuples) {
+        for (RepositoryTuple each : repositoryTuples) {
+            if (GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), 
each.getKey()).isPresent()) {
+                return Optional.of(YamlEngine.unmarshal(each.getValue(), 
YamlAuthorityRuleConfiguration.class));
+            }
+        }
+        return Optional.empty();
+    }
+    
     @Override
     public Optional<AuthorityRuleConfiguration> swapToObject(final 
Collection<RepositoryTuple> repositoryTuples) {
         for (RepositoryTuple each : repositoryTuples) {
diff --git 
a/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/GlobalClockRuleConfigurationRepositoryTupleSwapper.java
 
b/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/GlobalClockRuleConfigurationRepositoryTupleSwapper.java
index a352b226e75..f58a83a2824 100644
--- 
a/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/GlobalClockRuleConfigurationRepositoryTupleSwapper.java
+++ 
b/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/GlobalClockRuleConfigurationRepositoryTupleSwapper.java
@@ -41,6 +41,16 @@ public final class 
GlobalClockRuleConfigurationRepositoryTupleSwapper implements
         return Collections.singleton(new 
RepositoryTuple(getRuleTagName().toLowerCase(), 
YamlEngine.marshal(yamlRuleConfig)));
     }
     
+    @Override
+    public Optional<YamlGlobalClockRuleConfiguration> swapToObject0(final 
Collection<RepositoryTuple> repositoryTuples) {
+        for (RepositoryTuple each : repositoryTuples) {
+            if (GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), 
each.getKey()).isPresent()) {
+                return Optional.of(YamlEngine.unmarshal(each.getValue(), 
YamlGlobalClockRuleConfiguration.class));
+            }
+        }
+        return Optional.empty();
+    }
+    
     @Override
     public Optional<GlobalClockRuleConfiguration> swapToObject(final 
Collection<RepositoryTuple> repositoryTuples) {
         for (RepositoryTuple each : repositoryTuples) {
diff --git 
a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/swapper/LoggingRuleConfigurationRepositoryTupleSwapper.java
 
b/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/swapper/LoggingRuleConfigurationRepositoryTupleSwapper.java
index b63bed9dac2..97cccc84011 100644
--- 
a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/swapper/LoggingRuleConfigurationRepositoryTupleSwapper.java
+++ 
b/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/swapper/LoggingRuleConfigurationRepositoryTupleSwapper.java
@@ -41,6 +41,16 @@ public final class 
LoggingRuleConfigurationRepositoryTupleSwapper implements Rep
         return Collections.singleton(new 
RepositoryTuple(getRuleTagName().toLowerCase(), 
YamlEngine.marshal(yamlRuleConfig)));
     }
     
+    @Override
+    public Optional<YamlLoggingRuleConfiguration> swapToObject0(final 
Collection<RepositoryTuple> repositoryTuples) {
+        for (RepositoryTuple each : repositoryTuples) {
+            if (GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), 
each.getKey()).isPresent()) {
+                return Optional.of(YamlEngine.unmarshal(each.getValue(), 
YamlLoggingRuleConfiguration.class));
+            }
+        }
+        return Optional.empty();
+    }
+    
     @Override
     public Optional<LoggingRuleConfiguration> swapToObject(final 
Collection<RepositoryTuple> repositoryTuples) {
         for (RepositoryTuple each : repositoryTuples) {
diff --git 
a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/RepositoryTupleSwapperEngine.java
 
b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/RepositoryTupleSwapperEngine.java
index a47c441a565..9b607ce5ef8 100644
--- 
a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/RepositoryTupleSwapperEngine.java
+++ 
b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/RepositoryTupleSwapperEngine.java
@@ -20,6 +20,8 @@ package 
org.apache.shardingsphere.metadata.persist.service.config;
 import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
 import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
 import org.apache.shardingsphere.infra.util.yaml.datanode.RepositoryTuple;
+import 
org.apache.shardingsphere.infra.yaml.config.pojo.rule.YamlRuleConfiguration;
+import 
org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapperEngine;
 import org.apache.shardingsphere.mode.spi.RepositoryTupleSwapper;
 
 import java.util.Collection;
@@ -44,8 +46,9 @@ public final class RepositoryTupleSwapperEngine {
             return Collections.emptyList();
         }
         Collection<RuleConfiguration> result = new LinkedList<>();
+        YamlRuleConfigurationSwapperEngine yamlSwapperEngine = new 
YamlRuleConfigurationSwapperEngine();
         for (RepositoryTupleSwapper each : 
OrderedSPILoader.getServices(RepositoryTupleSwapper.class)) {
-            each.swapToObject(repositoryTuples).ifPresent(optional -> 
result.add((RuleConfiguration) optional));
+            each.swapToObject0(repositoryTuples).ifPresent(optional -> 
result.add(yamlSwapperEngine.swapToRuleConfiguration((YamlRuleConfiguration) 
optional)));
         }
         return result;
     }
@@ -59,9 +62,11 @@ public final class RepositoryTupleSwapperEngine {
      */
     @SuppressWarnings({"unchecked", "rawtypes"})
     public Optional<RuleConfiguration> swapToRuleConfiguration(final String 
ruleName, final Collection<RepositoryTuple> repositoryTuples) {
+        YamlRuleConfigurationSwapperEngine yamlSwapperEngine = new 
YamlRuleConfigurationSwapperEngine();
         for (RepositoryTupleSwapper each : 
OrderedSPILoader.getServices(RepositoryTupleSwapper.class)) {
             if (ruleName.equals(each.getRuleTagName().toLowerCase())) {
-                return each.swapToObject(repositoryTuples);
+                Optional<YamlRuleConfiguration> yamlRuleConfig = 
each.swapToObject0(repositoryTuples);
+                return 
yamlRuleConfig.map(yamlSwapperEngine::swapToRuleConfiguration);
             }
         }
         return Optional.empty();
diff --git 
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/yaml/config/swapper/SingleRuleConfigurationRepositoryTupleSwapper.java
 
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/yaml/config/swapper/SingleRuleConfigurationRepositoryTupleSwapper.java
index d127d4b4704..035bb70b1f4 100644
--- 
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/yaml/config/swapper/SingleRuleConfigurationRepositoryTupleSwapper.java
+++ 
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/yaml/config/swapper/SingleRuleConfigurationRepositoryTupleSwapper.java
@@ -45,6 +45,16 @@ public final class 
SingleRuleConfigurationRepositoryTupleSwapper implements Repo
         return Collections.singleton(new 
RepositoryTuple(SingleRuleNodePathProvider.TABLES, 
YamlEngine.marshal(yamlRuleConfig)));
     }
     
+    @Override
+    public Optional<YamlSingleRuleConfiguration> swapToObject0(final 
Collection<RepositoryTuple> repositoryTuples) {
+        for (RepositoryTuple each : repositoryTuples.stream().filter(each -> 
singleRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList()))
 {
+            if 
(singleRuleNodePath.getUniqueItem(SingleRuleNodePathProvider.TABLES).isValidatedPath(each.getKey()))
 {
+                return Optional.of(YamlEngine.unmarshal(each.getValue(), 
YamlSingleRuleConfiguration.class));
+            }
+        }
+        return Optional.empty();
+    }
+    
     @Override
     public Optional<SingleRuleConfiguration> swapToObject(final 
Collection<RepositoryTuple> repositoryTuples) {
         for (RepositoryTuple each : repositoryTuples.stream().filter(each -> 
singleRuleNodePath.getRoot().isValidatedPath(each.getKey())).collect(Collectors.toList()))
 {
diff --git 
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/SQLFederationRuleConfigurationRepositoryTupleSwapper.java
 
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/SQLFederationRuleConfigurationRepositoryTupleSwapper.java
index bee169e7301..65af70c026a 100644
--- 
a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/SQLFederationRuleConfigurationRepositoryTupleSwapper.java
+++ 
b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/SQLFederationRuleConfigurationRepositoryTupleSwapper.java
@@ -41,6 +41,16 @@ public final class 
SQLFederationRuleConfigurationRepositoryTupleSwapper implemen
         return Collections.singleton(new 
RepositoryTuple(getRuleTagName().toLowerCase(), 
YamlEngine.marshal(yamlRuleConfig)));
     }
     
+    @Override
+    public Optional<YamlSQLFederationRuleConfiguration> swapToObject0(final 
Collection<RepositoryTuple> repositoryTuples) {
+        for (RepositoryTuple each : repositoryTuples) {
+            if (GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), 
each.getKey()).isPresent()) {
+                return Optional.of(YamlEngine.unmarshal(each.getValue(), 
YamlSQLFederationRuleConfiguration.class));
+            }
+        }
+        return Optional.empty();
+    }
+    
     @Override
     public Optional<SQLFederationRuleConfiguration> swapToObject(final 
Collection<RepositoryTuple> repositoryTuples) {
         for (RepositoryTuple each : repositoryTuples) {
diff --git 
a/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/yaml/swapper/SQLParserRuleConfigurationRepositoryTupleSwapper.java
 
b/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/yaml/swapper/SQLParserRuleConfigurationRepositoryTupleSwapper.java
index 91d8200eedb..890e524eb35 100644
--- 
a/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/yaml/swapper/SQLParserRuleConfigurationRepositoryTupleSwapper.java
+++ 
b/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/yaml/swapper/SQLParserRuleConfigurationRepositoryTupleSwapper.java
@@ -41,6 +41,16 @@ public final class 
SQLParserRuleConfigurationRepositoryTupleSwapper implements R
         return Collections.singleton(new 
RepositoryTuple(getRuleTagName().toLowerCase(), 
YamlEngine.marshal(yamlRuleConfig)));
     }
     
+    @Override
+    public Optional<YamlSQLParserRuleConfiguration> swapToObject0(final 
Collection<RepositoryTuple> repositoryTuples) {
+        for (RepositoryTuple each : repositoryTuples) {
+            if (GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), 
each.getKey()).isPresent()) {
+                return Optional.of(YamlEngine.unmarshal(each.getValue(), 
YamlSQLParserRuleConfiguration.class));
+            }
+        }
+        return Optional.empty();
+    }
+    
     @Override
     public Optional<SQLParserRuleConfiguration> swapToObject(final 
Collection<RepositoryTuple> repositoryTuples) {
         for (RepositoryTuple each : repositoryTuples) {
diff --git 
a/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/SQLTranslatorRuleConfigurationRepositoryTupleSwapper.java
 
b/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/SQLTranslatorRuleConfigurationRepositoryTupleSwapper.java
index cc5bb8ff875..4b2da55ab9f 100644
--- 
a/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/SQLTranslatorRuleConfigurationRepositoryTupleSwapper.java
+++ 
b/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/SQLTranslatorRuleConfigurationRepositoryTupleSwapper.java
@@ -41,6 +41,16 @@ public final class 
SQLTranslatorRuleConfigurationRepositoryTupleSwapper implemen
         return Collections.singleton(new 
RepositoryTuple(getRuleTagName().toLowerCase(), 
YamlEngine.marshal(yamlRuleConfig)));
     }
     
+    @Override
+    public Optional<YamlSQLTranslatorRuleConfiguration> swapToObject0(final 
Collection<RepositoryTuple> repositoryTuples) {
+        for (RepositoryTuple each : repositoryTuples) {
+            if (GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), 
each.getKey()).isPresent()) {
+                return Optional.of(YamlEngine.unmarshal(each.getValue(), 
YamlSQLTranslatorRuleConfiguration.class));
+            }
+        }
+        return Optional.empty();
+    }
+    
     @Override
     public Optional<SQLTranslatorRuleConfiguration> swapToObject(final 
Collection<RepositoryTuple> repositoryTuples) {
         for (RepositoryTuple each : repositoryTuples) {
diff --git 
a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/yaml/swapper/TrafficRuleConfigurationRepositoryTupleSwapper.java
 
b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/yaml/swapper/TrafficRuleConfigurationRepositoryTupleSwapper.java
index de8f822e283..8c156db412e 100644
--- 
a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/yaml/swapper/TrafficRuleConfigurationRepositoryTupleSwapper.java
+++ 
b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/yaml/swapper/TrafficRuleConfigurationRepositoryTupleSwapper.java
@@ -41,6 +41,16 @@ public final class 
TrafficRuleConfigurationRepositoryTupleSwapper implements Rep
         return Collections.singleton(new 
RepositoryTuple(getRuleTagName().toLowerCase(), 
YamlEngine.marshal(yamlRuleConfig)));
     }
     
+    @Override
+    public Optional<YamlTrafficRuleConfiguration> swapToObject0(final 
Collection<RepositoryTuple> repositoryTuples) {
+        for (RepositoryTuple each : repositoryTuples) {
+            if (GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), 
each.getKey()).isPresent()) {
+                return Optional.of(YamlEngine.unmarshal(each.getValue(), 
YamlTrafficRuleConfiguration.class));
+            }
+        }
+        return Optional.empty();
+    }
+    
     @Override
     public Optional<TrafficRuleConfiguration> swapToObject(final 
Collection<RepositoryTuple> repositoryTuples) {
         for (RepositoryTuple each : repositoryTuples) {
diff --git 
a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/yaml/swapper/TransactionRuleConfigurationRepositoryTupleSwapper.java
 
b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/yaml/swapper/TransactionRuleConfigurationRepositoryTupleSwapper.java
index 896014d1334..2a097088814 100644
--- 
a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/yaml/swapper/TransactionRuleConfigurationRepositoryTupleSwapper.java
+++ 
b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/yaml/swapper/TransactionRuleConfigurationRepositoryTupleSwapper.java
@@ -41,6 +41,16 @@ public final class 
TransactionRuleConfigurationRepositoryTupleSwapper implements
         return Collections.singleton(new 
RepositoryTuple(getRuleTagName().toLowerCase(), 
YamlEngine.marshal(yamlRuleConfig)));
     }
     
+    @Override
+    public Optional<YamlTransactionRuleConfiguration> swapToObject0(final 
Collection<RepositoryTuple> repositoryTuples) {
+        for (RepositoryTuple each : repositoryTuples) {
+            if (GlobalNodePath.getVersion(getRuleTagName().toLowerCase(), 
each.getKey()).isPresent()) {
+                return Optional.of(YamlEngine.unmarshal(each.getValue(), 
YamlTransactionRuleConfiguration.class));
+            }
+        }
+        return Optional.empty();
+    }
+    
     @Override
     public Optional<TransactionRuleConfiguration> swapToObject(final 
Collection<RepositoryTuple> repositoryTuples) {
         for (RepositoryTuple each : repositoryTuples) {
diff --git 
a/mode/api/src/main/java/org/apache/shardingsphere/mode/spi/RepositoryTupleSwapper.java
 
b/mode/api/src/main/java/org/apache/shardingsphere/mode/spi/RepositoryTupleSwapper.java
index 40f4fb85322..4575d1163c3 100644
--- 
a/mode/api/src/main/java/org/apache/shardingsphere/mode/spi/RepositoryTupleSwapper.java
+++ 
b/mode/api/src/main/java/org/apache/shardingsphere/mode/spi/RepositoryTupleSwapper.java
@@ -43,6 +43,14 @@ public interface RepositoryTupleSwapper<T extends 
RuleConfiguration, Y extends Y
      */
     Collection<RepositoryTuple> swapToRepositoryTuples(Y yamlRuleConfig);
     
+    /**
+     * Swap from repository tuple to YAML rule configurations.
+     *
+     * @param repositoryTuples repository tuples
+     * @return swapped YAML rule configurations
+     */
+    Optional<Y> swapToObject0(Collection<RepositoryTuple> repositoryTuples);
+    
     /**
      * Swap from repository tuple to object.
      *

Reply via email to