This is an automated email from the ASF dual-hosted git repository. xiangweiwei pushed a commit to branch iotdb1303To0.12 in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit a0aae042ec9ddf16e539b928d34f6374b80df361 Author: Alima777 <[email protected]> AuthorDate: Thu Apr 15 19:11:04 2021 +0800 Fix iotdb1303 to rel/0.12 --- .../apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java | 9 +++++++++ .../iotdb/db/integration/IOTDBGroupByIT.java | 19 +++++++++++++++++++ .../iotdb/db/integration/IoTDBGroupByFillIT.java | 22 ++++++++++++++++++++++ .../aggregation/IoTDBAggregationByLevelIT.java | 19 +++++++++++++++++++ 4 files changed, 69 insertions(+) diff --git a/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java b/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java index cfd923b..62f12d9 100644 --- a/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java +++ b/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java @@ -1337,6 +1337,9 @@ public class IoTDBSqlVisitor extends SqlBaseBaseVisitor<Operator> { } public void parseGroupByLevelClause(GroupByLevelClauseContext ctx, QueryOperator queryOp) { + if (queryOp.getSelectOperator().getAggregations().isEmpty()) { + throw new SQLParserException("There is no aggregation function with group by query"); + } queryOp.setGroupByLevel(true); queryOp.setLevel(Integer.parseInt(ctx.INT().getText())); } @@ -1428,6 +1431,9 @@ public class IoTDBSqlVisitor extends SqlBaseBaseVisitor<Operator> { } private void parseGroupByTimeClause(GroupByTimeClauseContext ctx, QueryOperator queryOp) { + if (queryOp.getSelectOperator().getAggregations().isEmpty()) { + throw new SQLParserException("There is no aggregation function with group by query"); + } queryOp.setGroupByTime(true); queryOp.setLeftCRightO(ctx.timeInterval().LS_BRACKET() != null); // parse timeUnit @@ -1453,6 +1459,9 @@ public class IoTDBSqlVisitor extends SqlBaseBaseVisitor<Operator> { } private void parseGroupByFillClause(GroupByFillClauseContext ctx, QueryOperator queryOp) { + if (queryOp.getSelectOperator().getAggregations().isEmpty()) { + throw new SQLParserException("There is no aggregation function with group by query"); + } queryOp.setGroupByTime(true); queryOp.setFill(true); queryOp.setLeftCRightO(ctx.timeInterval().LS_BRACKET() != null); diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IOTDBGroupByIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IOTDBGroupByIT.java index 3d16ddf..c1f8779 100644 --- a/server/src/test/java/org/apache/iotdb/db/integration/IOTDBGroupByIT.java +++ b/server/src/test/java/org/apache/iotdb/db/integration/IOTDBGroupByIT.java @@ -931,6 +931,25 @@ public class IOTDBGroupByIT { } } + /** + * Test group by without aggregation function used in select clause. The expected situation is + * throwing an exception. + */ + @Test + public void TestGroupByWithoutAggregationFunc() { + try (Connection connection = + DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root"); + Statement statement = connection.createStatement()) { + + statement.execute("select temperature from root.ln.wf01.wt01 group by ([0, 100), 5ms)"); + + fail("No expected exception thrown"); + } catch (Exception e) { + Assert.assertTrue( + e.getMessage().contains("There is no aggregation function with group by query")); + } + } + private void prepareData() { try (Connection connection = DriverManager.getConnection( diff --git a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBGroupByFillIT.java b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBGroupByFillIT.java index 0257e0b..ba0e7c5 100644 --- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBGroupByFillIT.java +++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBGroupByFillIT.java @@ -24,6 +24,7 @@ import org.apache.iotdb.jdbc.Config; import org.apache.iotdb.jdbc.IoTDBSQLException; import org.junit.After; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -811,6 +812,27 @@ public class IoTDBGroupByFillIT { } } + /** + * Test group by fill without aggregation function used in select clause. The expected situation + * is throwing an exception. + */ + @Test + public void TestGroupByFillWithoutAggregationFunc() { + try (Connection connection = + DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root"); + Statement statement = connection.createStatement()) { + + statement.execute( + "select temperature from root.ln.wf01.wt01 " + + "group by ([0, 100), 5ms) FILL(int32[previous])"); + + fail("No expected exception thrown"); + } catch (Exception e) { + Assert.assertTrue( + e.getMessage().contains("There is no aggregation function with group by query")); + } + } + private void prepareData() { try (Connection connection = DriverManager.getConnection( diff --git a/server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationByLevelIT.java b/server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationByLevelIT.java index c1a7e14..a374612 100644 --- a/server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationByLevelIT.java +++ b/server/src/test/java/org/apache/iotdb/db/integration/aggregation/IoTDBAggregationByLevelIT.java @@ -322,6 +322,25 @@ public class IoTDBAggregationByLevelIT { } } + /** + * Test group by level without aggregation function used in select clause. The expected situation + * is throwing an exception. + */ + @Test + public void TestGroupByLevelWithoutAggregationFunc() { + try (Connection connection = + DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root"); + Statement statement = connection.createStatement()) { + + statement.execute("select temperature from root.sg1.* group by level = 2"); + + Assert.fail("No expected exception thrown"); + } catch (Exception e) { + Assert.assertTrue( + e.getMessage().contains("There is no aggregation function with group by query")); + } + } + private void prepareData() { try (Connection connection = DriverManager.getConnection(
