You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2022/11/02 11:08:54 UTC
[iotdb] 01/01: [IOTDB-4824] Fix error when insert a null value into a non-existed timeseries
This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch iotdb_4824
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 1c11ee87d2e4f2485c6d2525a6632c78921db086
Author: HTHou <hh...@outlook.com>
AuthorDate: Wed Nov 2 19:08:37 2022 +0800
[IOTDB-4824] Fix error when insert a null value into a non-existed timeseries
---
.../db/it/schema/IoTDBAutoCreateSchemaIT.java | 19 +++++++++++
.../db/mpp/plan/analyze/ClusterSchemaFetcher.java | 39 ++++++++++++----------
.../planner/plan/node/write/InsertRowNode.java | 3 +-
.../planner/plan/node/write/InsertTabletNode.java | 3 +-
4 files changed, 45 insertions(+), 19 deletions(-)
diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBAutoCreateSchemaIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBAutoCreateSchemaIT.java
index c26f1ddb59..cab57cadd9 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBAutoCreateSchemaIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBAutoCreateSchemaIT.java
@@ -201,4 +201,23 @@ public class IoTDBAutoCreateSchemaIT {
}
Assert.assertTrue(resultList.contains(storageGroup));
}
+
+ /**
+ * insert data when storage group hasn't been set, timeseries hasn't been created and have null
+ * values
+ */
+ @Test
+ public void testInsertAutoCreate3() {
+ String[] sqls = {
+ "INSERT INTO root.sg0.d3(timestamp,s1) values(1,null)",
+ "INSERT INTO root.sg0.d3(timestamp,s1,s2) values(1,null,2)",
+ };
+ for (String sql : sqls) {
+ try {
+ statement.execute(sql);
+ } catch (SQLException e) {
+ Assert.assertTrue(e.getMessage().contains("Path [root.sg0.d3.s1] does not exist"));
+ }
+ }
+ }
}
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/ClusterSchemaFetcher.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/ClusterSchemaFetcher.java
index c11970455a..22964f5ad4 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/ClusterSchemaFetcher.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/ClusterSchemaFetcher.java
@@ -390,25 +390,30 @@ public class ClusterSchemaFetcher implements ISchemaFetcher {
indexOfMissingMeasurements.forEach(
index -> {
TSDataType tsDataType = getDataType.apply(index);
- missingMeasurements.add(measurements[index]);
- dataTypesOfMissingMeasurement.add(tsDataType);
- encodingsOfMissingMeasurement.add(
- encodings == null ? getDefaultEncoding(tsDataType) : encodings[index]);
- compressionTypesOfMissingMeasurement.add(
- compressionTypes == null
- ? TSFileDescriptor.getInstance().getConfig().getCompressor()
- : compressionTypes[index]);
+ // tsDataType == null means insert null value to a non-exist series
+ // should skip creating them
+ if (tsDataType != null) {
+ missingMeasurements.add(measurements[index]);
+ dataTypesOfMissingMeasurement.add(tsDataType);
+ encodingsOfMissingMeasurement.add(
+ encodings == null ? getDefaultEncoding(tsDataType) : encodings[index]);
+ compressionTypesOfMissingMeasurement.add(
+ compressionTypes == null
+ ? TSFileDescriptor.getInstance().getConfig().getCompressor()
+ : compressionTypes[index]);
+ }
});
- schemaTree.mergeSchemaTree(
- internalCreateTimeseries(
- devicePath,
- missingMeasurements,
- dataTypesOfMissingMeasurement,
- encodingsOfMissingMeasurement,
- compressionTypesOfMissingMeasurement,
- isAligned));
-
+ if (!missingMeasurements.isEmpty()) {
+ schemaTree.mergeSchemaTree(
+ internalCreateTimeseries(
+ devicePath,
+ missingMeasurements,
+ dataTypesOfMissingMeasurement,
+ encodingsOfMissingMeasurement,
+ compressionTypesOfMissingMeasurement,
+ isAligned));
+ }
return schemaTree;
}
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertRowNode.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertRowNode.java
index 5f0b82eba9..8b544b5c17 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertRowNode.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertRowNode.java
@@ -42,6 +42,7 @@ import org.apache.iotdb.db.utils.TypeInferenceUtils;
import org.apache.iotdb.db.wal.buffer.IWALByteBufferView;
import org.apache.iotdb.db.wal.buffer.WALEntryValue;
import org.apache.iotdb.db.wal.utils.WALWriteUtils;
+import org.apache.iotdb.tsfile.common.constant.TsFileConstant;
import org.apache.iotdb.tsfile.exception.NotImplementedException;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.read.TimeValuePair;
@@ -188,7 +189,7 @@ public class InsertRowNode extends InsertNode implements WALEntryValue {
if (deviceSchemaInfo == null) {
throw new PathNotExistException(
Arrays.stream(measurements)
- .map(s -> devicePath.getFullPath() + s)
+ .map(s -> devicePath.getFullPath() + TsFileConstant.PATH_SEPARATOR + s)
.collect(Collectors.toList()));
}
if (deviceSchemaInfo.isAligned() != isAligned) {
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertTabletNode.java b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertTabletNode.java
index ba4f196ebf..29f563dd20 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertTabletNode.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertTabletNode.java
@@ -40,6 +40,7 @@ import org.apache.iotdb.db.utils.TimePartitionUtils;
import org.apache.iotdb.db.wal.buffer.IWALByteBufferView;
import org.apache.iotdb.db.wal.buffer.WALEntryValue;
import org.apache.iotdb.db.wal.utils.WALWriteUtils;
+import org.apache.iotdb.tsfile.common.constant.TsFileConstant;
import org.apache.iotdb.tsfile.exception.NotImplementedException;
import org.apache.iotdb.tsfile.exception.write.UnSupportedDataTypeException;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
@@ -182,7 +183,7 @@ public class InsertTabletNode extends InsertNode implements WALEntryValue {
if (deviceSchemaInfo == null) {
throw new PathNotExistException(
Arrays.stream(measurements)
- .map(s -> devicePath.getFullPath() + s)
+ .map(s -> devicePath.getFullPath() + TsFileConstant.PATH_SEPARATOR + s)
.collect(Collectors.toList()));
}
if (deviceSchemaInfo.isAligned() != isAligned) {