You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/12/29 08:36:06 UTC
[shardingsphere] branch master updated: Fix unsigned flag of metadata was not serialized (#23160)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 da91fd0de08 Fix unsigned flag of metadata was not serialized (#23160)
da91fd0de08 is described below
commit da91fd0de08551c0bd552fb1622192dfa7cb453d
Author: 吴伟杰 <wu...@apache.org>
AuthorDate: Thu Dec 29 16:35:57 2022 +0800
Fix unsigned flag of metadata was not serialized (#23160)
---
.../yaml/schema/swapper/YamlTableSwapper.java | 1 +
.../yaml/schema/swapper/YamlSchemaSwapperTest.java | 32 ++++++++++++++++------
.../src/test/resources/yaml/schema/schema.yaml | 4 +++
3 files changed, 28 insertions(+), 9 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 1ecb8e110dc..7b201faabe6 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
@@ -110,6 +110,7 @@ public final class YamlTableSwapper implements YamlConfigurationSwapper<YamlShar
result.setPrimaryKey(column.isPrimaryKey());
result.setDataType(column.getDataType());
result.setVisible(column.isVisible());
+ result.setUnsigned(column.isUnsigned());
return result;
}
}
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/YamlSchemaSwapperTest.java
index e0072e0ae6f..483cfdfc233 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/YamlSchemaSwapperTest.java
@@ -18,7 +18,9 @@
package org.apache.shardingsphere.infra.yaml.schema.swapper;
import lombok.SneakyThrows;
+import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereColumn;
import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
+import org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereTable;
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.YamlShardingSphereSchema;
@@ -34,8 +36,8 @@ import java.util.Map;
import java.util.stream.Collectors;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertFalse;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public final class YamlSchemaSwapperTest {
@@ -51,10 +53,10 @@ public final class YamlSchemaSwapperTest {
assertThat(yamlSchema.getTables().keySet(), is(Collections.singleton("t_order")));
YamlShardingSphereTable yamlTableMetaData = yamlSchema.getTables().get("t_order");
assertThat(yamlTableMetaData.getIndexes().keySet(), is(Collections.singleton("primary")));
- assertColumn(yamlTableMetaData.getColumns());
+ assertYamlColumn(yamlTableMetaData.getColumns());
}
- private void assertColumn(final Map<String, YamlShardingSphereColumn> columns) {
+ private void assertYamlColumn(final Map<String, YamlShardingSphereColumn> columns) {
assertThat(columns.size(), is(2));
YamlShardingSphereColumn idColumn = columns.get("id");
assertThat(idColumn.getName(), is("id"));
@@ -62,23 +64,35 @@ public final class YamlSchemaSwapperTest {
assertThat(idColumn.getDataType(), is(0));
assertFalse(idColumn.isGenerated());
assertTrue(idColumn.isPrimaryKey());
+ assertFalse(idColumn.isUnsigned());
+ assertTrue(idColumn.isVisible());
YamlShardingSphereColumn nameColumn = columns.get("name");
assertThat(nameColumn.getName(), is("name"));
assertTrue(nameColumn.isCaseSensitive());
assertThat(nameColumn.getDataType(), is(10));
assertTrue(nameColumn.isGenerated());
assertFalse(nameColumn.isPrimaryKey());
+ assertTrue(nameColumn.isUnsigned());
+ assertFalse(nameColumn.isVisible());
}
@Test
public void assertSwapToShardingSphereSchema() {
YamlShardingSphereSchema yamlSchema = YamlEngine.unmarshal(readYAML(YAML), YamlShardingSphereSchema.class);
- ShardingSphereSchema schema = new YamlSchemaSwapper().swapToObject(yamlSchema);
- assertThat(schema.getAllTableNames(), is(Collections.singleton("t_order")));
- assertThat(schema.getTable("t_order").getIndexes().keySet(), is(Collections.singleton("primary")));
- assertThat(schema.getAllColumnNames("t_order").size(), is(2));
- assertTrue(schema.containsColumn("t_order", "id"));
- assertTrue(schema.containsColumn("t_order", "name"));
+ ShardingSphereSchema actualSchema = new YamlSchemaSwapper().swapToObject(yamlSchema);
+ assertThat(actualSchema.getAllTableNames(), is(Collections.singleton("t_order")));
+ ShardingSphereTable actualTable = actualSchema.getTable("t_order");
+ assertColumn(actualTable);
+ assertThat(actualTable.getIndexes().keySet(), is(Collections.singleton("primary")));
+ assertThat(actualSchema.getAllColumnNames("t_order").size(), is(2));
+ assertTrue(actualSchema.containsColumn("t_order", "id"));
+ assertTrue(actualSchema.containsColumn("t_order", "name"));
+ }
+
+ private void assertColumn(final ShardingSphereTable table) {
+ assertThat(table.getColumns().size(), is(2));
+ assertThat(table.getColumns().get("id"), is(new ShardingSphereColumn("id", 0, true, false, false, true, false)));
+ assertThat(table.getColumns().get("name"), is(new ShardingSphereColumn("name", 10, false, true, true, false, true)));
}
@Test
diff --git a/infra/common/src/test/resources/yaml/schema/schema.yaml b/infra/common/src/test/resources/yaml/schema/schema.yaml
index 730887d10c4..35bb4429961 100644
--- a/infra/common/src/test/resources/yaml/schema/schema.yaml
+++ b/infra/common/src/test/resources/yaml/schema/schema.yaml
@@ -24,12 +24,16 @@ tables:
generated: false
name: id
primaryKey: true
+ unsigned: false
+ visible: true
name:
caseSensitive: true
dataType: 10
generated: true
name: name
primaryKey: false
+ unsigned: true
+ visible: false
indexes:
primary:
name: PRIMARY