Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,22 @@ public void templateInvalidTest() {
"select count(s1+1) from root.sg1.** align by device;", expectedHeader, retArray);
}

@Test
public void emptyResultTest() {
String[] expectedHeader = new String[] {"Time,Device,s3,s1,s2"};
String[] retArray = new String[] {};
resultSetEqualTest(
"SELECT * FROM root.sg1.** where time>=now()-1d and time<=now() "
+ "ORDER BY TIME DESC ALIGN BY DEVICE;",
expectedHeader,
retArray);
resultSetEqualTest(
"SELECT * FROM root.sg2.** where time>=now()-1d and time<=now() "
+ "ORDER BY TIME DESC ALIGN BY DEVICE;",
expectedHeader,
retArray);
}

private static void insertData() {
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public class TopKOperator implements ProcessOperator {
// the data of every childOperator is in order
private final boolean childrenDataInOrder;

public static int operatorBatchUpperBound = 100000;

public TopKOperator(
OperatorContext operatorContext,
List<Operator> deviceOperators,
Expand All @@ -98,7 +100,10 @@ public TopKOperator(

initResultTsBlock();

deviceBatchStep = 10000 % topValue == 0 ? 10000 / topValue : 10000 / topValue + 1;
deviceBatchStep =
operatorBatchUpperBound % topValue == 0
? operatorBatchUpperBound / topValue
: operatorBatchUpperBound / topValue + 1;
canCallNext = new boolean[deviceOperators.size()];
}

Expand Down Expand Up @@ -137,7 +142,14 @@ public boolean isFinished() throws Exception {

@Override
public boolean hasNext() throws Exception {
return !(deviceIndex >= deviceOperators.size() && resultReturnSize >= topKResult.length);
if (deviceIndex >= deviceOperators.size()) {
if (topKResult == null) {
return false;
}

return resultReturnSize < topKResult.length;
}
return true;
}

@Override
Expand Down Expand Up @@ -289,10 +301,13 @@ private TsBlock getResultFromCachedTopKResult() {
}

tsBlockBuilder.reset();

if (topKResult == null || topKResult.length == 0) {
return tsBlockBuilder.build();
}

ColumnBuilder[] valueColumnBuilders = tsBlockBuilder.getValueColumnBuilders();
for (int i = resultReturnSize, size = (topKResult == null ? 0 : topKResult.length);
i < size;
i++) {
for (int i = resultReturnSize; i < topKResult.length; i++) {
MergeSortKey mergeSortKey = topKResult[i];
TsBlock targetBlock = mergeSortKey.tsBlock;
tsBlockBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public static boolean canBuildPlanUseTemplate(
// generate result set header according to output expressions
analyzeOutput(analysis, queryStatement, outputExpressions);

context.generateGlobalTimeFilter(analysis);
// fetch partition information
analyzeDataPartition(analysis, schemaTree, partitionFetcher, context.getGlobalTimeFilter());
return true;
Expand Down
Loading