This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 70bc300f725 Remove useless YamlSchemaSwapper (#33250)
70bc300f725 is described below
commit 70bc300f725bf2858b36f2e08d572ebd45d2180b
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Oct 15 11:34:59 2024 +0800
Remove useless YamlSchemaSwapper (#33250)
---
.../yaml/schema/swapper/YamlSchemaSwapper.java | 80 ----------------------
...aSwapperTest.java => YamlTableSwapperTest.java} | 36 +++++-----
.../yaml/schema/swapper/YamlViewSwapperTest.java | 65 ++++++++++++++++++
.../yaml/schema/{schema.yaml => empty-table.yaml} | 29 ++------
.../yaml/schema/{empty-schema.yaml => table.yaml} | 19 ++++-
.../yaml/schema/{empty-schema.yaml => view.yaml} | 3 +-
6 files changed, 106 insertions(+), 126 deletions(-)
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlSchemaSwapper.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlSchemaSwapper.java
deleted file mode 100644
index 0d5bee46f56..00000000000
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlSchemaSwapper.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.infra.yaml.schema.swapper;
-
-import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
-import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
-import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereView;
-import
org.apache.shardingsphere.infra.util.yaml.swapper.YamlConfigurationSwapper;
-import
org.apache.shardingsphere.infra.yaml.schema.pojo.YamlShardingSphereSchema;
-import
org.apache.shardingsphere.infra.yaml.schema.pojo.YamlShardingSphereTable;
-import org.apache.shardingsphere.infra.yaml.schema.pojo.YamlShardingSphereView;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-/**
- * YAML schema swapper.
- */
-public final class YamlSchemaSwapper implements
YamlConfigurationSwapper<YamlShardingSphereSchema, ShardingSphereSchema> {
-
- @Override
- public YamlShardingSphereSchema swapToYamlConfiguration(final
ShardingSphereSchema schema) {
- Map<String, YamlShardingSphereTable> tables =
schema.getAllTableNames().stream()
- .collect(Collectors.toMap(each -> each, each ->
swapYamlTable(schema.getTable(each)), (oldValue, currentValue) -> oldValue,
LinkedHashMap::new));
- Map<String, YamlShardingSphereView> views =
schema.getAllViewNames().stream()
- .collect(Collectors.toMap(each -> each, each ->
swapYamlView(schema.getView(each)), (oldValue, currentValue) -> oldValue,
LinkedHashMap::new));
- YamlShardingSphereSchema result = new YamlShardingSphereSchema();
- result.setName(schema.getName());
- result.setTables(tables);
- result.setViews(views);
- return result;
- }
-
- @Override
- public ShardingSphereSchema swapToObject(final YamlShardingSphereSchema
yamlConfig) {
- return
Optional.ofNullable(yamlConfig).map(this::swapSchema).orElseGet(() -> new
ShardingSphereSchema(yamlConfig.getName()));
- }
-
- private ShardingSphereSchema swapSchema(final YamlShardingSphereSchema
schema) {
- Map<String, ShardingSphereTable> tables = null == schema.getTables()
|| schema.getTables().isEmpty() ? new LinkedHashMap<>()
- :
schema.getTables().entrySet().stream().collect(Collectors.toMap(Entry::getKey,
entry -> swapTable(entry.getValue()), (oldValue, currentValue) -> oldValue,
LinkedHashMap::new));
- Map<String, ShardingSphereView> views = null == schema.getViews() ||
schema.getViews().isEmpty() ? new LinkedHashMap<>()
- :
schema.getViews().entrySet().stream().collect(Collectors.toMap(Entry::getKey,
entry -> swapView(entry.getValue()), (oldValue, currentValue) -> oldValue,
LinkedHashMap::new));
- return new ShardingSphereSchema(schema.getName(), tables, views);
- }
-
- private ShardingSphereTable swapTable(final YamlShardingSphereTable table)
{
- return new YamlTableSwapper().swapToObject(table);
- }
-
- private YamlShardingSphereTable swapYamlTable(final ShardingSphereTable
table) {
- return new YamlTableSwapper().swapToYamlConfiguration(table);
- }
-
- private ShardingSphereView swapView(final YamlShardingSphereView view) {
- return new YamlViewSwapper().swapToObject(view);
- }
-
- private YamlShardingSphereView swapYamlView(final ShardingSphereView view)
{
- return new YamlViewSwapper().swapToYamlConfiguration(view);
- }
-}
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlSchemaSwapperTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlTableSwapperTest.java
similarity index 67%
rename from
infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlSchemaSwapperTest.java
rename to
infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlTableSwapperTest.java
index d7610814cb1..f5d7ab8be9b 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlSchemaSwapperTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlTableSwapperTest.java
@@ -21,11 +21,9 @@ import lombok.SneakyThrows;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereConstraint;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereIndex;
-import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
-import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereView;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import
org.apache.shardingsphere.infra.yaml.schema.pojo.YamlShardingSphereSchema;
+import
org.apache.shardingsphere.infra.yaml.schema.pojo.YamlShardingSphereTable;
import org.junit.jupiter.api.Test;
import java.io.IOException;
@@ -38,48 +36,46 @@ import java.util.stream.Collectors;
import static
org.apache.shardingsphere.test.matcher.ShardingSphereAssertionMatchers.deepEqual;
import static org.hamcrest.MatcherAssert.assertThat;
-class YamlSchemaSwapperTest {
+class YamlTableSwapperTest {
- private static final String YAML_FILE = "yaml/schema/schema.yaml";
+ private static final String YAML_FILE = "yaml/schema/table.yaml";
- private static final String EMPTY_YAML_FILE =
"yaml/schema/empty-schema.yaml";
+ private static final String EMPTY_YAML_FILE =
"yaml/schema/empty-table.yaml";
- private final YamlSchemaSwapper swapper = new YamlSchemaSwapper();
+ private final YamlTableSwapper swapper = new YamlTableSwapper();
@Test
void assertSwapToYamlConfiguration() {
- ShardingSphereSchema schema = createShardingSphereSchema();
- YamlShardingSphereSchema actual =
swapper.swapToYamlConfiguration(schema);
- YamlShardingSphereSchema expected = unmarshal(YAML_FILE);
+ ShardingSphereTable table = createShardingSphereTable();
+ YamlShardingSphereTable actual =
swapper.swapToYamlConfiguration(table);
+ YamlShardingSphereTable expected = unmarshal(YAML_FILE);
assertThat(actual, deepEqual(expected));
}
@Test
void assertSwapToObject() {
- ShardingSphereSchema actual =
swapper.swapToObject(unmarshal(YAML_FILE));
- ShardingSphereSchema expected = createShardingSphereSchema();
+ ShardingSphereTable actual =
swapper.swapToObject(unmarshal(YAML_FILE));
+ ShardingSphereTable expected = createShardingSphereTable();
assertThat(actual, deepEqual(expected));
}
@Test
void assertSwapToObjectWithEmptySchema() {
- ShardingSphereSchema actual =
swapper.swapToObject(unmarshal(EMPTY_YAML_FILE));
- ShardingSphereSchema expected = new ShardingSphereSchema("foo_schema");
+ ShardingSphereTable actual =
swapper.swapToObject(unmarshal(EMPTY_YAML_FILE));
+ ShardingSphereTable expected = new ShardingSphereTable();
assertThat(actual, deepEqual(expected));
}
@SneakyThrows({URISyntaxException.class, IOException.class})
- private YamlShardingSphereSchema unmarshal(final String yamlFile) {
+ private YamlShardingSphereTable unmarshal(final String yamlFile) {
String yamlContent =
Files.readAllLines(Paths.get(ClassLoader.getSystemResource(yamlFile).toURI())).stream().collect(Collectors.joining(System.lineSeparator()));
- return YamlEngine.unmarshal(yamlContent,
YamlShardingSphereSchema.class);
+ return YamlEngine.unmarshal(yamlContent,
YamlShardingSphereTable.class);
}
- private ShardingSphereSchema createShardingSphereSchema() {
- ShardingSphereTable table = new ShardingSphereTable(null,
+ 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.singleton(new
ShardingSphereConstraint("foo_constraint", "foo_tbl")), null);
- ShardingSphereView view = new ShardingSphereView("foo_view", "SELECT
1");
- return new ShardingSphereSchema("foo_schema",
Collections.singletonMap("foo_tbl", table),
Collections.singletonMap("foo_view", view));
}
}
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlViewSwapperTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlViewSwapperTest.java
new file mode 100644
index 00000000000..73ea43ff4e2
--- /dev/null
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/schema/swapper/YamlViewSwapperTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.infra.yaml.schema.swapper;
+
+import lombok.SneakyThrows;
+import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereView;
+import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
+import org.apache.shardingsphere.infra.yaml.schema.pojo.YamlShardingSphereView;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.stream.Collectors;
+
+import static
org.apache.shardingsphere.test.matcher.ShardingSphereAssertionMatchers.deepEqual;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+class YamlViewSwapperTest {
+
+ private static final String YAML_FILE = "yaml/schema/view.yaml";
+
+ private final YamlViewSwapper swapper = new YamlViewSwapper();
+
+ @Test
+ void assertSwapToYamlConfiguration() {
+ ShardingSphereView view = createShardingSphereView();
+ YamlShardingSphereView actual = swapper.swapToYamlConfiguration(view);
+ YamlShardingSphereView expected = unmarshal(YAML_FILE);
+ assertThat(actual, deepEqual(expected));
+ }
+
+ @Test
+ void assertSwapToObject() {
+ ShardingSphereView actual = swapper.swapToObject(unmarshal(YAML_FILE));
+ ShardingSphereView expected = createShardingSphereView();
+ assertThat(actual, deepEqual(expected));
+ }
+
+ @SneakyThrows({URISyntaxException.class, IOException.class})
+ private YamlShardingSphereView unmarshal(final String yamlFile) {
+ String yamlContent =
Files.readAllLines(Paths.get(ClassLoader.getSystemResource(yamlFile).toURI())).stream().collect(Collectors.joining(System.lineSeparator()));
+ return YamlEngine.unmarshal(yamlContent, YamlShardingSphereView.class);
+ }
+
+ private ShardingSphereView createShardingSphereView() {
+ return new ShardingSphereView("foo_view", "SELECT 1");
+ }
+}
diff --git a/infra/common/src/test/resources/yaml/schema/schema.yaml
b/infra/common/src/test/resources/yaml/schema/empty-table.yaml
similarity index 61%
rename from infra/common/src/test/resources/yaml/schema/schema.yaml
rename to infra/common/src/test/resources/yaml/schema/empty-table.yaml
index ba3b22b9f2d..c3f52cebee4 100644
--- a/infra/common/src/test/resources/yaml/schema/schema.yaml
+++ b/infra/common/src/test/resources/yaml/schema/empty-table.yaml
@@ -15,27 +15,8 @@
# limitations under the License.
#
-name: foo_schema
-tables:
- foo_tbl:
- columns:
- foo_col:
- name: foo_col
- dataType: 0
- primaryKey: true
- generated: false
- caseSensitive: false
- visible: true
- unsigned: false
- nullable: false
- indexes:
- primary:
- name: PRIMARY
- constraints:
- foo_constraint:
- name: foo_constraint
- referencedTableName: foo_tbl
-views:
- foo_view:
- name: foo_view
- viewDefinition: SELECT 1
+name: ''
+type: TABLE
+columns:
+indexes:
+constraints:
diff --git a/infra/common/src/test/resources/yaml/schema/empty-schema.yaml
b/infra/common/src/test/resources/yaml/schema/table.yaml
similarity index 70%
copy from infra/common/src/test/resources/yaml/schema/empty-schema.yaml
copy to infra/common/src/test/resources/yaml/schema/table.yaml
index c4d034348b0..adb4a9a552c 100644
--- a/infra/common/src/test/resources/yaml/schema/empty-schema.yaml
+++ b/infra/common/src/test/resources/yaml/schema/table.yaml
@@ -15,4 +15,21 @@
# limitations under the License.
#
-name: foo_schema
+name: foo_tbl
+columns:
+ foo_col:
+ name: foo_col
+ dataType: 0
+ primaryKey: true
+ generated: false
+ caseSensitive: false
+ visible: true
+ unsigned: false
+ nullable: false
+indexes:
+ primary:
+ name: PRIMARY
+constraints:
+ foo_constraint:
+ name: foo_constraint
+ referencedTableName: foo_tbl
diff --git a/infra/common/src/test/resources/yaml/schema/empty-schema.yaml
b/infra/common/src/test/resources/yaml/schema/view.yaml
similarity index 95%
rename from infra/common/src/test/resources/yaml/schema/empty-schema.yaml
rename to infra/common/src/test/resources/yaml/schema/view.yaml
index c4d034348b0..a0460852948 100644
--- a/infra/common/src/test/resources/yaml/schema/empty-schema.yaml
+++ b/infra/common/src/test/resources/yaml/schema/view.yaml
@@ -15,4 +15,5 @@
# limitations under the License.
#
-name: foo_schema
+name: foo_view
+viewDefinition: SELECT 1