Skip to content

Commit 2488001

Browse files
authored
SeriesScanUtil throws exception when using filters that could not match any time range (apache#16691)
1 parent 69cda2d commit 2488001

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBFilterIT.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.iotdb.itbase.category.ClusterIT;
2525

2626
import org.junit.AfterClass;
27+
import org.junit.Assert;
2728
import org.junit.BeforeClass;
2829
import org.junit.Test;
2930
import org.junit.experimental.categories.Category;
@@ -238,4 +239,17 @@ public void testFilterWithUDTF() {
238239
fail(throwable.getMessage());
239240
}
240241
}
242+
243+
@Test
244+
public void testFilterWithEmptySatisfiedTimeRanges() {
245+
try (Connection connection = EnvFactory.getEnv().getConnection();
246+
Statement statement = connection.createStatement();
247+
ResultSet resultSet =
248+
statement.executeQuery("select count(*) from root.** where time >= 0 and time < 0")) {
249+
Assert.assertTrue(resultSet.next());
250+
Assert.assertEquals(0, resultSet.getInt(1));
251+
} catch (SQLException throwable) {
252+
fail(throwable.getMessage());
253+
}
254+
}
241255
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5480,4 +5480,15 @@ public void emptyBlockInStreamOperatorTest() {
54805480
retArray,
54815481
DATABASE_NAME);
54825482
}
5483+
5484+
@Test
5485+
public void emptyTimeRangeQueryTest() {
5486+
String[] expectedHeader = new String[] {"_col0"};
5487+
String[] retArray = new String[] {"0,"};
5488+
tableResultSetEqualTest(
5489+
"select count(*) from table1 where time >= 0 and time < -1",
5490+
expectedHeader,
5491+
retArray,
5492+
DATABASE_NAME);
5493+
}
54835494
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/SeriesScanUtil.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ public void initQueryDataSource(QueryDataSource dataSource) {
219219
orderUtils.setCurSeqFileIndex(dataSource);
220220
curUnseqFileIndex = 0;
221221

222+
if (dataSource.isEmpty()) {
223+
// no satisfied resources
224+
return;
225+
}
226+
222227
if (satisfiedTimeRange == null) {
223228
long startTime = Long.MAX_VALUE;
224229
long endTime = Long.MIN_VALUE;

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/QueryDataSource.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ public List<TsFileResource> getUnseqResources() {
100100
return unseqResources;
101101
}
102102

103+
public boolean isEmpty() {
104+
return (seqResources == null || seqResources.isEmpty())
105+
&& (unseqResources == null || unseqResources.isEmpty());
106+
}
107+
103108
@Override
104109
public IQueryDataSource clone() {
105110
QueryDataSource queryDataSource =

0 commit comments

Comments
 (0)