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 2021/08/02 13:07:02 UTC
[iotdb] branch master updated: skip non exist measurement in where
clause (#3590) (#3665)
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 635a43e skip non exist measurement in where clause (#3590) (#3665)
635a43e is described below
commit 635a43e27200fc547f0db26533f5b0c047fdcdee
Author: zyk990424 <38...@users.noreply.github.com>
AuthorDate: Mon Aug 2 21:06:39 2021 +0800
skip non exist measurement in where clause (#3590) (#3665)
---
.../iotdb/db/qp/logical/crud/QueryOperator.java | 24 ++++++++--
.../iotdb/db/integration/IoTDBAlignByDeviceIT.java | 54 ++++++++++++++++++++++
2 files changed, 73 insertions(+), 5 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/QueryOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/QueryOperator.java
index 0813832..98f4d6f 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/QueryOperator.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/QueryOperator.java
@@ -19,6 +19,7 @@
package org.apache.iotdb.db.qp.logical.crud;
import org.apache.iotdb.db.exception.metadata.MetadataException;
+import org.apache.iotdb.db.exception.metadata.PathNotExistException;
import org.apache.iotdb.db.exception.query.LogicalOperatorException;
import org.apache.iotdb.db.exception.query.LogicalOptimizeException;
import org.apache.iotdb.db.exception.query.QueryProcessException;
@@ -45,6 +46,7 @@ import org.apache.iotdb.tsfile.read.expression.IExpression;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@@ -403,9 +405,16 @@ public class QueryOperator extends Operator {
throws QueryProcessException {
Map<String, IExpression> deviceToFilterMap = new HashMap<>();
Set<PartialPath> filterPaths = new HashSet<>();
- for (PartialPath device : devices) {
+ Iterator<PartialPath> deviceIterator = devices.iterator();
+ while (deviceIterator.hasNext()) {
+ PartialPath device = deviceIterator.next();
FilterOperator newOperator = operator.copy();
- concatFilterPath(device, newOperator, filterPaths);
+ try {
+ concatFilterPath(device, newOperator, filterPaths);
+ } catch (PathNotExistException e) {
+ deviceIterator.remove();
+ continue;
+ }
// transform to a list so it can be indexed
List<PartialPath> filterPathList = new ArrayList<>(filterPaths);
try {
@@ -426,7 +435,8 @@ public class QueryOperator extends Operator {
}
private void concatFilterPath(
- PartialPath prefix, FilterOperator operator, Set<PartialPath> filterPaths) {
+ PartialPath prefix, FilterOperator operator, Set<PartialPath> filterPaths)
+ throws PathNotExistException {
if (!operator.isLeaf()) {
for (FilterOperator child : operator.getChildren()) {
concatFilterPath(prefix, child, filterPaths);
@@ -444,8 +454,12 @@ public class QueryOperator extends Operator {
}
PartialPath concatPath = prefix.concatPath(filterPath);
- filterPaths.add(concatPath);
- basicOperator.setSinglePath(concatPath);
+ if (IoTDB.metaManager.isPathExist(concatPath)) {
+ filterPaths.add(concatPath);
+ basicOperator.setSinglePath(concatPath);
+ } else {
+ throw new PathNotExistException(concatPath.getFullPath());
+ }
}
protected Set<PartialPath> getMatchedDevices(PartialPath path) throws MetadataException {
diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAlignByDeviceIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAlignByDeviceIT.java
index f901b97..40a2932 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAlignByDeviceIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBAlignByDeviceIT.java
@@ -1273,4 +1273,58 @@ public class IoTDBAlignByDeviceIT {
fail(e.getMessage());
}
}
+
+ @Test
+ public void selectWithNonExistMeasurementInWhereClause() throws ClassNotFoundException {
+ String[] retArray =
+ new String[] {
+ "1,root.vehicle.d0,101,1101,null,null,null,",
+ };
+
+ Class.forName(Config.JDBC_DRIVER_NAME);
+ try (Connection connection =
+ DriverManager.getConnection(
+ Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
+ Statement statement = connection.createStatement()) {
+ boolean hasResultSet =
+ statement.execute("select * from root.vehicle.* where s1 == 1101 align by device");
+ Assert.assertTrue(hasResultSet);
+
+ try (ResultSet resultSet = statement.getResultSet()) {
+ ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
+ List<Integer> actualIndexToExpectedIndexList =
+ checkHeader(
+ resultSetMetaData,
+ "Time,Device,s0,s1,s2,s3,s4",
+ new int[] {
+ Types.TIMESTAMP,
+ Types.VARCHAR,
+ Types.INTEGER,
+ Types.BIGINT,
+ Types.FLOAT,
+ Types.VARCHAR,
+ Types.BOOLEAN
+ });
+
+ int cnt = 0;
+ while (resultSet.next()) {
+ String[] expectedStrings = retArray[cnt].split(",");
+ StringBuilder expectedBuilder = new StringBuilder();
+ StringBuilder actualBuilder = new StringBuilder();
+ for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
+ actualBuilder.append(resultSet.getString(i)).append(",");
+ expectedBuilder
+ .append(expectedStrings[actualIndexToExpectedIndexList.get(i - 1)])
+ .append(",");
+ }
+ Assert.assertEquals(expectedBuilder.toString(), actualBuilder.toString());
+ cnt++;
+ }
+ Assert.assertEquals(1, cnt);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
}