This is an automated email from the ASF dual-hosted git repository. caogaofei pushed a commit to branch fix_negative_agg in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 548ae7cee9270e07856fbb882c26906a5c439da6 Author: Beyyes <[email protected]> AuthorDate: Tue Nov 7 20:28:47 2023 +0800 fix negative value aggregation error --- .../apache/iotdb/db/it/IoTDBInsertWithQueryIT.java | 23 ++++++++++++++++++++++ .../execution/operator/AggregationUtil.java | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBInsertWithQueryIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBInsertWithQueryIT.java index 403aa35fcef..2ef61ed7b28 100644 --- a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBInsertWithQueryIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBInsertWithQueryIT.java @@ -37,6 +37,7 @@ import java.sql.Statement; import java.util.ArrayList; import java.util.List; +import static org.apache.iotdb.db.it.utils.TestUtils.resultSetEqualTest; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; @@ -159,6 +160,8 @@ public class IoTDBInsertWithQueryIT { // select selectAndCount(2001); + + negativeTimestampAggregationTest(); } @Test @@ -480,4 +483,24 @@ public class IoTDBInsertWithQueryIT { fail(e.getMessage()); } } + + private void negativeTimestampAggregationTest() { + String[] expectedHeader = new String[] {"count(root.fans.d0.s0)"}; + String[] retArray = new String[] {"2001,"}; + resultSetEqualTest("SELECT count(s0) FROM root.fans.d0;", expectedHeader, retArray); + + expectedHeader = new String[] {"count(root.fans.d0.s0)"}; + retArray = new String[] {"1999,"}; + resultSetEqualTest( + "SELECT count(s0) FROM root.fans.d0 WHERE time<-1;", expectedHeader, retArray); + + expectedHeader = new String[] {"min_time(root.fans.d0.s0)"}; + retArray = new String[] {"-2000,"}; + resultSetEqualTest("SELECT min_time(s0) FROM root.fans.d0;", expectedHeader, retArray); + + expectedHeader = new String[] {"max_time(root.fans.d0.s0)"}; + retArray = new String[] {"-2,"}; + resultSetEqualTest( + "SELECT max_time(s0) FROM root.fans.d0 WHERE time<-1;", expectedHeader, retArray); + } } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/AggregationUtil.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/AggregationUtil.java index b72ad3c6da6..07e30824165 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/AggregationUtil.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/AggregationUtil.java @@ -68,7 +68,7 @@ public class AggregationUtil { boolean ascending, boolean outputPartialTimeWindow) { if (groupByTimeParameter == null) { - return new SingleTimeWindowIterator(0, Long.MAX_VALUE); + return new SingleTimeWindowIterator(Long.MIN_VALUE, Long.MAX_VALUE); } else { return TimeRangeIteratorFactory.getTimeRangeIterator( groupByTimeParameter.getStartTime(),
