From d8a7ea6bc9e7d53fa1b313138b9acb267bbf3f8e Mon Sep 17 00:00:00 2001 From: SilverNarcissus <151250176@smail.nju.edu.cn> Date: Fri, 18 Oct 2019 11:27:27 +0800 Subject: [PATCH] [IOTDB-240] fix unknown time series in where clause (#443) * fix querying non-existing paths in where clause" --- .../org/apache/iotdb/db/metadata/MTree.java | 3 +- .../optimizer/ConcatPathOptimizer.java | 5 ++- .../db/integration/IoTDBMultiSeriesIT.java | 42 +++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java b/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java index db25f001bf..7df2b71522 100644 --- a/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java +++ b/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java @@ -512,8 +512,7 @@ public class MTree implements Serializable { MNode cur = getRoot(); for (int i = 1; i < nodes.length; i++) { if (!cur.hasChild(nodes[i])) { - throw new PathErrorException( - String.format(NO_CHILD_ERROR,cur.getName(),nodes[i])); + throw new PathErrorException("Path: \"" + path + "\" doesn't correspond to any known time series"); } cur = cur.getChild(nodes[i]); } diff --git a/server/src/main/java/org/apache/iotdb/db/qp/strategy/optimizer/ConcatPathOptimizer.java b/server/src/main/java/org/apache/iotdb/db/qp/strategy/optimizer/ConcatPathOptimizer.java index 05ee489263..36cd0c137e 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/strategy/optimizer/ConcatPathOptimizer.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/strategy/optimizer/ConcatPathOptimizer.java @@ -276,6 +276,9 @@ public class ConcatPathOptimizer implements ILogicalOptimizer { for (Path path : paths) { List all; all = executor.getAllPaths(path.getFullPath()); + if(all.isEmpty()){ + throw new LogicalOptimizeException("Path: \"" + path + "\" doesn't correspond to any known time series"); + } for (String subPath : all) { if (!pathMap.containsKey(subPath)) { pathMap.put(subPath, 1); @@ -299,7 +302,7 @@ public class ConcatPathOptimizer implements ILogicalOptimizer { try { List actualPaths = executor.getAllPaths(paths.get(i).getFullPath()); if(actualPaths.isEmpty()){ - throw new LogicalOptimizeException("Path: \"" + paths.get(i) + "\" not corresponding any known time series"); + throw new LogicalOptimizeException("Path: \"" + paths.get(i) + "\" doesn't correspond to any known time series"); } for (String actualPath : actualPaths) { retPaths.add(new Path(actualPath)); diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBMultiSeriesIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBMultiSeriesIT.java index c40a70e8e9..6a98ad99b5 100644 --- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBMultiSeriesIT.java +++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBMultiSeriesIT.java @@ -334,4 +334,46 @@ public class IoTDBMultiSeriesIT { fail(e.getMessage()); } } + + @Test + public void selectUnknownTimeSeries() throws ClassNotFoundException { + 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()) { + statement.execute("select s10 from root.vehicle.d0"); + fail("not throw exception when select unknown time series"); + } catch (SQLException e) { + assertEquals("Execute statement error: Path: \"root.vehicle.d0.s10\" doesn't correspond to any known time series", e.getMessage()); + } + } + + @Test + public void selectWhereUnknownTimeSeries() throws ClassNotFoundException { + 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()) { + statement.execute("select s1 from root.vehicle.d0 where s0 < 111 and s10 < 111"); + fail("not throw exception when unknown time series in where clause"); + } catch (SQLException e) { + assertEquals("Execute statement error: Path: \"root.vehicle.d0.s10\" doesn't correspond to any known time series", e.getMessage()); + } + } + + @Test + public void selectWhereUnknownTimeSeriesFromRoot() throws ClassNotFoundException { + 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()) { + statement.execute("select s1 from root.vehicle.d0 where root.vehicle.d0.s0 < 111 and root.vehicle.d0.s10 < 111"); + fail("not throw exception when unknown time series in where clause"); + } catch (SQLException e) { + assertEquals("Execute statement error: Path: \"root.vehicle.d0.s10\" doesn't correspond to any known time series", e.getMessage()); + } + } } -- GitLab