Skip to content

Commit 796de65

Browse files
authored
Fix case of process empty block in Streaming(Hash)AggregationOperator
1 parent 74a75fd commit 796de65

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBTableAggregationIT.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5246,4 +5246,26 @@ public void exceptionTest2() {
52465246

52475247
tableAssertTestFail("select * from table1 where (s1,s2) is not null", errMsg, DATABASE_NAME);
52485248
}
5249+
5250+
@Test
5251+
public void emptyBlockInStreamOperatorTest() {
5252+
String[] expectedHeader = new String[] {"_col0"};
5253+
String[] retArray = new String[] {};
5254+
5255+
// the sub-query produces empty block
5256+
5257+
// test StreamingHashAggregationOperator
5258+
tableResultSetEqualTest(
5259+
"select count(1) from (select * from table1 where s1 + 1 < 1) group by device_id,s1",
5260+
expectedHeader,
5261+
retArray,
5262+
DATABASE_NAME);
5263+
5264+
// test StreamingAggregationOperator
5265+
tableResultSetEqualTest(
5266+
"select count(1) from (select * from table1 where s1 + 1 < 1) group by device_id",
5267+
expectedHeader,
5268+
retArray,
5269+
DATABASE_NAME);
5270+
}
52495271
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/grouped/StreamingAggregationOperator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public TsBlock next() throws Exception {
122122
TsBlock block;
123123
if (child.hasNextWithTimer()) {
124124
block = child.nextWithTimer();
125-
if (block == null) {
125+
if (block == null || block.isEmpty()) {
126126
return null;
127127
}
128128

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/aggregation/grouped/StreamingHashAggregationOperator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public TsBlock next() throws Exception {
159159
TsBlock block;
160160
if (child.hasNextWithTimer()) {
161161
block = child.nextWithTimer();
162-
if (block == null) {
162+
if (block == null || block.isEmpty()) {
163163
return null;
164164
}
165165

0 commit comments

Comments
 (0)