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 2019/12/01 01:21:08 UTC
[incubator-iotdb] branch master updated: fix a bug about groupby
query
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/incubator-iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 28558f9 fix a bug about groupby query
new fb3b828 Merge pull request #602 from LeiRui/bugfix
28558f9 is described below
commit 28558f92cb831c27dba1b36dac20670f4d6bc356
Author: Lei Rui <10...@qq.com>
AuthorDate: Sat Nov 30 18:10:00 2019 +0800
fix a bug about groupby query
---
.../dataset/groupby/GroupByEngineDataSet.java | 5 +++-
.../iotdb/db/integration/IOTDBGroupByIT.java | 30 ++++++++++++++++++++++
2 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/GroupByEngineDataSet.java b/server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/GroupByEngineDataSet.java
index b49a7ea..3e73c37 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/GroupByEngineDataSet.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/GroupByEngineDataSet.java
@@ -23,9 +23,9 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.iotdb.db.exception.path.PathException;
import org.apache.iotdb.db.metadata.MManager;
-import org.apache.iotdb.db.query.factory.AggreFuncFactory;
import org.apache.iotdb.db.query.aggregation.AggreResultData;
import org.apache.iotdb.db.query.aggregation.AggregateFunction;
+import org.apache.iotdb.db.query.factory.AggreFuncFactory;
import org.apache.iotdb.tsfile.exception.write.UnSupportedDataTypeException;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.read.common.Field;
@@ -103,6 +103,9 @@ public abstract class GroupByEngineDataSet extends QueryDataSet {
startTime = mergedIntervals.get(usedIndex).left;
if (origin > startTime) {
endTime = origin - (origin - startTime) / unit * unit;
+ if (endTime == startTime) { // origin - startTime is an integral multiple of unit
+ endTime += unit;
+ }
} else {
endTime = origin + (startTime - origin) / unit * unit + unit;
}
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 d54a1e0..a1d5b92 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
@@ -152,6 +152,17 @@ public class IOTDBGroupByIT {
"145,1,200.2,200.2",
"310,0,0.0,null"
};
+ String[] retArray3 = new String[]{
+ "5,3,35.8,11.933333333333332",
+ "25,1,30.3,30.3",
+ "50,1,50.5,50.5",
+ "65,0,0.0,null",
+ "85,1,100.1,100.1",
+ "105,0,0.0,null",
+ "125,0,0.0,null",
+ "145,1,200.2,200.2",
+ "310,0,0.0,null"
+ };
try (Connection connection = DriverManager.
getConnection("jdbc:iotdb://127.0.0.1:6667/", "root", "root");
Statement statement = connection.createStatement()) {
@@ -194,6 +205,25 @@ public class IOTDBGroupByIT {
Assert.assertEquals(retArray2.length, cnt);
}
+ hasResultSet = statement.execute(
+ "select count(temperature), sum(temperature), avg(temperature) from "
+ + "root.ln.wf01.wt01 where temperature > 3 "
+ + "GROUP BY (20ms, 25,[5,30], [35,37], [50, 160], [310, 314])");
+
+ Assert.assertTrue(hasResultSet);
+ try (ResultSet resultSet = statement.getResultSet()) {
+ cnt = 0;
+ while (resultSet.next()) {
+ String ans = resultSet.getString(TIMESTAMP_STR) + "," + resultSet
+ .getString(count("root.ln.wf01.wt01.temperature")) + "," +
+ resultSet.getString(sum("root.ln.wf01.wt01.temperature")) + "," + resultSet
+ .getString(avg("root.ln.wf01.wt01.temperature"));
+ Assert.assertEquals(retArray3[cnt], ans);
+ cnt++;
+ }
+ Assert.assertEquals(retArray3.length, cnt);
+ }
+
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());