You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by qi...@apache.org on 2020/11/07 07:24:41 UTC
[iotdb] branch master updated: [IOTDB-987]Add plan integrity check
(#1969)
This is an automated email from the ASF dual-hosted git repository.
qiaojialin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 8e0315d [IOTDB-987]Add plan integrity check (#1969)
8e0315d is described below
commit 8e0315dd5214da5b91ccf236eaaddeef19a90123
Author: Jiang Tian <jt...@163.com>
AuthorDate: Sat Nov 7 15:24:24 2020 +0800
[IOTDB-987]Add plan integrity check (#1969)
---
.../apache/iotdb/db/qp/executor/PlanExecutor.java | 13 -----------
.../apache/iotdb/db/qp/physical/PhysicalPlan.java | 11 +++++++++
.../iotdb/db/qp/physical/crud/InsertPlan.java | 18 +++++++++++++++
.../iotdb/db/qp/physical/crud/InsertRowPlan.java | 26 ++++++++++++++++++++--
.../db/qp/physical/crud/InsertTabletPlan.java | 17 ++++++++++++++
.../org/apache/iotdb/db/service/TSServiceImpl.java | 1 +
6 files changed, 71 insertions(+), 15 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java b/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
index e8fe6ad..6172e8c 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
@@ -865,19 +865,6 @@ public class PlanExecutor implements IPlanExecutor {
@Override
public void insert(InsertRowPlan insertRowPlan) throws QueryProcessException {
try {
-
- // check insert plan
- if (insertRowPlan.getMeasurements() == null) {
- throw new QueryProcessException(
- "The measurements of InsertRowPlan is null, deviceId:" + insertRowPlan.getDeviceId()
- + ", time:" + insertRowPlan.getTime());
- }
- if (insertRowPlan.getValues().length == 0) {
- throw new QueryProcessException(
- "The size of values in this InsertRowPlan is 0, deviceId:" + insertRowPlan.getDeviceId()
- + ", time:" + insertRowPlan.getTime());
- }
-
insertRowPlan
.setMeasurementMNodes(new MeasurementMNode[insertRowPlan.getMeasurements().length]);
getSeriesSchemas(insertRowPlan);
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java
index 649bbac..9dfec98 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java
@@ -24,6 +24,7 @@ import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.List;
import org.apache.iotdb.db.exception.metadata.IllegalPathException;
+import org.apache.iotdb.db.exception.query.QueryProcessException;
import org.apache.iotdb.db.metadata.PartialPath;
import org.apache.iotdb.db.qp.logical.Operator;
import org.apache.iotdb.db.qp.logical.Operator.OperatorType;
@@ -308,4 +309,14 @@ public abstract class PhysicalPlan {
public void setIndex(long index) {
this.index = index;
}
+
+
+ /**
+ * Check the integrity of the plan in case that the plan is generated by a careless user
+ * through Session API.
+ * @throws QueryProcessException when the check fails
+ */
+ public void checkIntegrity() throws QueryProcessException {
+
+ }
}
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertPlan.java
index 8d1daed..8a7b59f 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertPlan.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertPlan.java
@@ -20,11 +20,15 @@
package org.apache.iotdb.db.qp.physical.crud;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
+import org.apache.iotdb.db.exception.query.QueryProcessException;
+import org.apache.iotdb.db.metadata.MetaUtils;
import org.apache.iotdb.db.metadata.PartialPath;
import org.apache.iotdb.db.metadata.mnode.MeasurementMNode;
import org.apache.iotdb.db.qp.logical.Operator;
import org.apache.iotdb.db.qp.physical.PhysicalPlan;
+import org.apache.iotdb.db.utils.SchemaUtils;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
public abstract class InsertPlan extends PhysicalPlan {
@@ -141,4 +145,18 @@ public abstract class InsertPlan extends PhysicalPlan {
return this;
}
+ @Override
+ public void checkIntegrity() throws QueryProcessException {
+ if (deviceId == null) {
+ throw new QueryProcessException("DeviceId is null");
+ }
+ if (measurements == null) {
+ throw new QueryProcessException("Measurements are null");
+ }
+ for (String measurement : measurements) {
+ if (measurement == null || measurement.isEmpty()) {
+ throw new QueryProcessException("Measurement contains null or empty string: " + Arrays.toString(measurements));
+ }
+ }
+ }
}
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertRowPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertRowPlan.java
index b41311e..47f5afa 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertRowPlan.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertRowPlan.java
@@ -443,7 +443,8 @@ public class InsertRowPlan extends InsertPlan {
@Override
public String toString() {
- return "deviceId: " + deviceId + ", time: " + time;
+ return "deviceId: " + deviceId + ", time: " + time + ", measurements: " + Arrays
+ .toString(measurements) + ", values: " + Arrays.toString(values);
}
public TimeValuePair composeTimeValuePair(int measurementIndex) {
@@ -452,7 +453,8 @@ public class InsertRowPlan extends InsertPlan {
}
Object value = values[measurementIndex];
return new TimeValuePair(time,
- TsPrimitiveType.getByType(measurementMNodes[measurementIndex].getSchema().getType(), value));
+ TsPrimitiveType
+ .getByType(measurementMNodes[measurementIndex].getSchema().getType(), value));
}
@Override
@@ -464,4 +466,24 @@ public class InsertRowPlan extends InsertPlan {
failedValues = null;
return this;
}
+
+ @Override
+ public void checkIntegrity() throws QueryProcessException {
+ super.checkIntegrity();
+ if (values == null) {
+ throw new QueryProcessException("Values are null");
+ }
+ if (values.length == 0) {
+ throw new QueryProcessException("The size of values is 0");
+ }
+ if (measurements.length != values.length) {
+ throw new QueryProcessException(String.format("Measurements length [%d] does not match "
+ + "values length [%d]", measurements.length, values.length));
+ }
+ for (Object value : values) {
+ if (value == null) {
+ throw new QueryProcessException("Values contain null: " + Arrays.toString(values));
+ }
+ }
+ }
}
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertTabletPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertTabletPlan.java
index a1ff094..daa9d84 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertTabletPlan.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/InsertTabletPlan.java
@@ -26,6 +26,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import org.apache.iotdb.db.exception.metadata.IllegalPathException;
+import org.apache.iotdb.db.exception.query.QueryProcessException;
import org.apache.iotdb.db.metadata.PartialPath;
import org.apache.iotdb.db.qp.logical.Operator.OperatorType;
import org.apache.iotdb.db.utils.QueryDataSetUtils;
@@ -574,4 +575,20 @@ public class InsertTabletPlan extends InsertPlan {
return result;
}
+ @Override
+ public void checkIntegrity() throws QueryProcessException {
+ super.checkIntegrity();
+ if (columns == null) {
+ throw new QueryProcessException("Values are null");
+ }
+ if (measurements.length != columns.length) {
+ throw new QueryProcessException(String.format("Measurements length [%d] does not match "
+ + "columns length [%d]", measurements.length, columns.length));
+ }
+ for (Object value : columns) {
+ if (value == null) {
+ throw new QueryProcessException("Columns contain null: " + Arrays.toString(columns));
+ }
+ }
+ }
}
diff --git a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
index 67372c6..595f59e 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
@@ -1740,6 +1740,7 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
protected TSStatus executeNonQueryPlan(PhysicalPlan plan) {
boolean execRet;
try {
+ plan.checkIntegrity();
execRet = executeNonQuery(plan);
} catch (BatchInsertionException e) {
return RpcUtils.getStatus(Arrays.asList(e.getFailingStatus()));