This is an automated email from the ASF dual-hosted git repository.
qiaojialin pushed a commit to branch rel/0.11
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/rel/0.11 by this push:
new 002f7c0 [To rel/0.11] [IOTDB-1303] Group by without aggregation
function used in select clause (#3018)
002f7c0 is described below
commit 002f7c0a0350b2adf93d43b5264a271aa610f3f0
Author: Xiangwei Wei <[email protected]>
AuthorDate: Mon Apr 19 20:34:44 2021 +0800
[To rel/0.11] [IOTDB-1303] Group by without aggregation function used in
select clause (#3018)
---
.../apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java | 9 +++++++++
.../iotdb/db/integration/IOTDBGroupByIT.java | 19 +++++++++++++++++++
.../iotdb/db/integration/IoTDBGroupByFillIT.java | 22 ++++++++++++++++++++++
3 files changed, 50 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 d50ac52..92ed310 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
@@ -1010,6 +1010,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()));
}
@@ -1097,6 +1100,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
@@ -1119,6 +1125,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 f2989ec..c589416 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
@@ -801,6 +801,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(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root",
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 b217ecd..e7fd1c6 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
@@ -33,6 +33,7 @@ import org.apache.iotdb.db.utils.EnvironmentUtils;
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;
@@ -788,6 +789,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(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root",