Skip to content

Commit efe975f

Browse files
committed
Skip empty TsBlocks in operator tests
1 parent 13fe459 commit efe975f

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/OffsetOperatorTest.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import java.util.concurrent.TimeUnit;
6666

6767
import static org.apache.iotdb.db.queryengine.execution.fragment.FragmentInstanceContext.createFragmentInstanceContext;
68+
import static org.apache.iotdb.db.queryengine.execution.operator.OperatorTestUtils.isNullOrEmpty;
6869
import static org.apache.iotdb.db.queryengine.execution.operator.OperatorTestUtils.nextNonNull;
6970
import static org.junit.Assert.assertEquals;
7071
import static org.junit.Assert.assertTrue;
@@ -383,11 +384,11 @@ public void batchTest3() throws Exception {
383384
new OffsetOperator(driverContext.getOperatorContexts().get(3), 500, timeJoinOperator);
384385

385386
while (offsetOperator.isBlocked().isDone() && offsetOperator.hasNext()) {
386-
TsBlock tsBlock = nextNonNull(offsetOperator);
387-
assertEquals(2, tsBlock.getValueColumnCount());
388-
assertTrue(tsBlock.getColumn(0) instanceof IntColumn);
389-
assertTrue(tsBlock.getColumn(1) instanceof IntColumn);
390-
assertEquals(0, tsBlock.getPositionCount());
387+
TsBlock tsBlock = offsetOperator.next();
388+
if (isNullOrEmpty(tsBlock)) {
389+
continue;
390+
}
391+
fail("Expected no data from offset operator");
391392
}
392393
} catch (IllegalPathException e) {
393394
e.printStackTrace();
@@ -475,11 +476,11 @@ public void batchTest4() throws Exception {
475476
driverContext.getOperatorContexts().get(3), 98_784_247_808L, timeJoinOperator);
476477

477478
while (offsetOperator.isBlocked().isDone() && offsetOperator.hasNext()) {
478-
TsBlock tsBlock = nextNonNull(offsetOperator);
479-
assertEquals(2, tsBlock.getValueColumnCount());
480-
assertTrue(tsBlock.getColumn(0) instanceof IntColumn);
481-
assertTrue(tsBlock.getColumn(1) instanceof IntColumn);
482-
assertEquals(0, tsBlock.getPositionCount());
479+
TsBlock tsBlock = offsetOperator.next();
480+
if (isNullOrEmpty(tsBlock)) {
481+
continue;
482+
}
483+
fail("Expected no data from offset operator");
483484
}
484485
} catch (IllegalPathException e) {
485486
e.printStackTrace();

iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/execution/operator/OperatorTestUtils.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,25 @@ private OperatorTestUtils() {
3131
public static TsBlock nextNonNull(Operator operator) throws Exception {
3232
while (operator.hasNext()) {
3333
TsBlock result = operator.next();
34-
if (result != null) {
34+
if (!isNullOrEmpty(result)) {
3535
return result;
3636
}
3737
}
38-
throw new AssertionError("Expected a non-null TsBlock from operator");
38+
throw new AssertionError("Expected a non-empty TsBlock from operator");
3939
}
4040

4141
public static TsBlock lastNonNull(Operator operator) throws Exception {
4242
TsBlock result = null;
4343
while (operator.isBlocked().isDone() && operator.hasNext()) {
4444
TsBlock nextResult = operator.next();
45-
if (nextResult != null) {
45+
if (!isNullOrEmpty(nextResult)) {
4646
result = nextResult;
4747
}
4848
}
4949
return result;
5050
}
51+
52+
public static boolean isNullOrEmpty(TsBlock tsBlock) {
53+
return tsBlock == null || tsBlock.getPositionCount() == 0;
54+
}
5155
}

0 commit comments

Comments
 (0)