diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/utils/TestUtils.java b/integration-test/src/test/java/org/apache/iotdb/db/it/utils/TestUtils.java index 9c2a09024c4d9..93f14dc572b55 100644 --- a/integration-test/src/test/java/org/apache/iotdb/db/it/utils/TestUtils.java +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/utils/TestUtils.java @@ -1055,16 +1055,15 @@ public static void executeNonQueries(BaseEnv env, List sqlList) { null); } - public static void executeNonQueries( - BaseEnv env, List sqlList, Connection defaultConnection) { + public static void executeNonQueries(BaseEnv env, List sqlList, String sqlDialect) { executeNonQueries( env, sqlList, SessionConfig.DEFAULT_USER, SessionConfig.DEFAULT_PASSWORD, null, - TREE_SQL_DIALECT, - defaultConnection); + sqlDialect, + null); } public static void executeNonQueries( diff --git a/integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/tablemodel/manual/enhanced/IoTDBPipeMetaIT.java b/integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/tablemodel/manual/enhanced/IoTDBPipeMetaIT.java index 936ca1f50974d..f26aa171ae11b 100644 --- a/integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/tablemodel/manual/enhanced/IoTDBPipeMetaIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/tablemodel/manual/enhanced/IoTDBPipeMetaIT.java @@ -232,8 +232,7 @@ public void testNoTree() throws Exception { "create database root.test", "alter database root.test with schema_region_group_num=2, data_region_group_num=3", "create timeSeries root.test.d1.s1 int32", - "insert into root.test.d1 (s1) values (1)"), - null); + "insert into root.test.d1 (s1) values (1)")); TestUtils.assertDataAlwaysOnEnv( receiverEnv, @@ -418,4 +417,35 @@ public void testValidation() throws Exception { } } } + + @Test + public void testAttributeSync() { + TestUtils.executeNonQueries( + receiverEnv, + Arrays.asList( + "create database test", + "use test", + "create table table1(a tag, b attribute, c attribute, d int32)", + "insert into table1 (time, a, b, c, d) values(1, 1, null, 1, 1), (2, 2, 2, null, 2)"), + BaseEnv.TABLE_SQL_DIALECT); + + TestUtils.executeNonQueries( + senderEnv, + Arrays.asList( + "create database test", + "use test", + "create table table1(a tag, b attribute, c attribute, d int32)", + "insert into table1 (time, a, b, c, d) values(1, 1, 1, null, 1), (2, 2, null, 2, 2)", + String.format( + "create pipe a2b with source ('inclusion'='schema') with sink ('node-urls'='%s')", + receiverEnv.getDataNodeWrapperList().get(0).getIpAndPortString())), + BaseEnv.TABLE_SQL_DIALECT); + + TestUtils.assertDataAlwaysOnEnv( + receiverEnv, + "show devices from table1", + "a,b,c,", + new HashSet<>(Arrays.asList("1,1,1,", "2,2,2,")), + "test"); + } } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/node/schema/CreateOrUpdateTableDeviceNode.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/node/schema/CreateOrUpdateTableDeviceNode.java index be4b1337e7e4c..1ee49df2bdf42 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/node/schema/CreateOrUpdateTableDeviceNode.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/node/schema/CreateOrUpdateTableDeviceNode.java @@ -31,6 +31,7 @@ import org.apache.iotdb.db.schemaengine.schemaregion.SchemaRegionPlanVisitor; import org.apache.tsfile.file.metadata.IDeviceID; +import org.apache.tsfile.utils.Constants; import org.apache.tsfile.utils.ReadWriteIOUtils; import java.io.DataOutputStream; @@ -215,7 +216,7 @@ protected void serializeAttributes(final DataOutputStream stream) throws IOExcep ReadWriteIOUtils.writeObject(value, stream); } for (int i = 0; i < attributeNameList.size() - deviceAttributeValueList.length; ++i) { - ReadWriteIOUtils.writeObject(null, stream); + ReadWriteIOUtils.writeObject(Constants.NONE, stream); } } } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/attribute/DeviceAttributeStore.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/attribute/DeviceAttributeStore.java index ee0b5f98c8a2c..4349a7a49f144 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/attribute/DeviceAttributeStore.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/attribute/DeviceAttributeStore.java @@ -27,6 +27,7 @@ import org.apache.iotdb.db.schemaengine.schemaregion.attribute.update.UpdateDetailContainer; import org.apache.tsfile.utils.Binary; +import org.apache.tsfile.utils.Constants; import org.apache.tsfile.utils.RamUsageEstimator; import org.apache.tsfile.utils.ReadWriteIOUtils; import org.slf4j.Logger; @@ -163,6 +164,12 @@ public Map alterAttribute( final Map attributeMap = deviceAttributeList.get(pointer); for (int i = 0; i < nameList.size(); i++) { final String key = nameList.get(i); + if (valueList.length <= i) { + break; + } + if (valueList[i] == Constants.NONE) { + continue; + } final Binary value = (Binary) valueList[i]; originMemUsage = diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/schema/SRStatementGenerator.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/schema/SRStatementGenerator.java index 239b55b521b1b..aa478491f1920 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/schema/SRStatementGenerator.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/tools/schema/SRStatementGenerator.java @@ -45,6 +45,7 @@ import org.apache.iotdb.db.schemaengine.schemaregion.mtree.impl.mem.snapshot.MemMTreeSnapshotUtil; import org.apache.tsfile.utils.Binary; +import org.apache.tsfile.utils.Constants; import org.apache.tsfile.utils.Pair; import org.apache.tsfile.utils.ReadWriteIOUtils; import org.slf4j.Logger; @@ -447,7 +448,13 @@ private List genActivateTemplateOrUpdateDeviceStatement( attributeNameList = new ArrayList<>(tableAttributes.keySet()); } final List attributeValues = - attributeNameList.stream().map(tableAttributes::remove).collect(Collectors.toList()); + attributeNameList.stream() + .map( + attributeKey -> { + final Object attributeValue = tableAttributes.remove(attributeKey); + return Objects.nonNull(attributeValue) ? attributeValue : Constants.NONE; + }) + .collect(Collectors.toList()); tableAttributes.forEach( (attributeKey, attributeValue) -> { attributeNameList.add(attributeKey); diff --git a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/SchemaRegionSnapshotParserTest.java b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/SchemaRegionSnapshotParserTest.java index 471a02c70b704..c7cbc78d21039 100644 --- a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/SchemaRegionSnapshotParserTest.java +++ b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/SchemaRegionSnapshotParserTest.java @@ -48,6 +48,7 @@ import org.apache.tsfile.file.metadata.enums.CompressionType; import org.apache.tsfile.file.metadata.enums.TSEncoding; import org.apache.tsfile.utils.Binary; +import org.apache.tsfile.utils.Constants; import org.apache.tsfile.utils.Pair; import org.junit.After; import org.junit.Assert; @@ -313,7 +314,9 @@ public void testTableDeviceAttributeTranslateSnapshot() throws Exception { Arrays.asList("a", "c"), Arrays.asList( new Binary[] {new Binary("b", TSFileConfig.STRING_CHARSET)}, - new Binary[] {null, new Binary("d", TSFileConfig.STRING_CHARSET)})), + new Object[] { + Constants.NONE, new Binary("d", TSFileConfig.STRING_CHARSET) + })), new CreateOrUpdateDevice( databasePath.getNodes()[1], anotherTable, diff --git a/pom.xml b/pom.xml index 1763a519f9efe..dc46047da2efd 100644 --- a/pom.xml +++ b/pom.xml @@ -163,7 +163,7 @@ 0.14.1 1.9 1.5.6-3 - 2.2.1-260327-SNAPSHOT + 2.3.0-260422-SNAPSHOT