This is an automated email from the ASF dual-hosted git repository. jiangtian pushed a commit to branch add_plan_integrity_check in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 17fa904e8521100131a63e1fa337be51bd9f061f Author: jt <[email protected]> AuthorDate: Fri Nov 6 17:15:50 2020 +0800 add plan integrity check --- .../apache/iotdb/db/qp/physical/PhysicalPlan.java | 11 +++++++++++ .../iotdb/db/qp/physical/crud/InsertPlan.java | 18 +++++++++++++++++ .../iotdb/db/qp/physical/crud/InsertRowPlan.java | 23 ++++++++++++++++++++-- .../db/qp/physical/crud/InsertTabletPlan.java | 17 ++++++++++++++++ .../org/apache/iotdb/db/service/TSServiceImpl.java | 1 + 5 files changed, 68 insertions(+), 2 deletions(-) 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..227d828 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,21 @@ 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 (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 67fceec..95007e9 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 @@ -1741,6 +1741,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()));
