This is an automated email from the ASF dual-hosted git repository.

qiaojialin pushed a commit to branch rel/0.12
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/rel/0.12 by this push:
     new 4a3ef0c  [To rel/0.12] [IOTDB-1303] Group by without aggregation 
function used in select clause (#3019)
4a3ef0c is described below

commit 4a3ef0c041800c4b8b15ab6f526f7053aee27896
Author: Xiangwei Wei <[email protected]>
AuthorDate: Mon Apr 19 20:35:19 2021 +0800

    [To rel/0.12] [IOTDB-1303] Group by without aggregation function used in 
select clause (#3019)
---
 .../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..9783ab1 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.hasAggregation()) {
+      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.hasAggregation()) {
+      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.hasAggregation()) {
+      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..b9d0bd7c 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..3ac4c8e 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..7565822 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(

Reply via email to