This is an automated email from the ASF dual-hosted git repository.

jackietien pushed a commit to branch new_object_type
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit eae73aae64aa050c795c2ec1598b3fd7c680582b
Author: shuwenwei <[email protected]>
AuthorDate: Tue Nov 4 10:22:33 2025 +0800

    SeriesScanUtil throws exception when using filters that could not match any 
time range (#16691)
    
    (cherry picked from commit 2488001e8087ef76821ae1782cd54ff1d8b416f7)
---
 .../test/java/org/apache/iotdb/db/it/IoTDBFilterIT.java    | 14 ++++++++++++++
 .../it/query/recent/IoTDBTableAggregationIT.java           | 11 +++++++++++
 .../execution/operator/source/SeriesScanUtil.java          |  5 +++++
 .../db/storageengine/dataregion/read/QueryDataSource.java  |  5 +++++
 4 files changed, 35 insertions(+)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBFilterIT.java 
b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBFilterIT.java
index 306346e2bdc..b8dd88ea9d7 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBFilterIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBFilterIT.java
@@ -24,6 +24,7 @@ import org.apache.iotdb.it.framework.IoTDBTestRunner;
 import org.apache.iotdb.itbase.category.ClusterIT;
 
 import org.junit.AfterClass;
+import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -238,4 +239,17 @@ public class IoTDBFilterIT {
       fail(throwable.getMessage());
     }
   }
+
+  @Test
+  public void testFilterWithEmptySatisfiedTimeRanges() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement();
+        ResultSet resultSet =
+            statement.executeQuery("select count(*) from root.** where time >= 
0 and time < 0")) {
+      Assert.assertTrue(resultSet.next());
+      Assert.assertEquals(0, resultSet.getInt(1));
+    } catch (SQLException throwable) {
+      fail(throwable.getMessage());
+    }
+  }
 }
diff --git 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBTableAggregationIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBTableAggregationIT.java
index c6e5fc138ce..0143bdb6e3b 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBTableAggregationIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/recent/IoTDBTableAggregationIT.java
@@ -5480,4 +5480,15 @@ public class IoTDBTableAggregationIT {
         retArray,
         DATABASE_NAME);
   }
+
+  @Test
+  public void emptyTimeRangeQueryTest() {
+    String[] expectedHeader = new String[] {"_col0"};
+    String[] retArray = new String[] {"0,"};
+    tableResultSetEqualTest(
+        "select count(*) from table1 where time >= 0 and time < -1",
+        expectedHeader,
+        retArray,
+        DATABASE_NAME);
+  }
 }
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/SeriesScanUtil.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/SeriesScanUtil.java
index b49b9b199d1..e2fbb4be4ec 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/SeriesScanUtil.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/SeriesScanUtil.java
@@ -219,6 +219,11 @@ public class SeriesScanUtil implements Accountable {
     orderUtils.setCurSeqFileIndex(dataSource);
     curUnseqFileIndex = 0;
 
+    if (dataSource.isEmpty()) {
+      // no satisfied resources
+      return;
+    }
+
     if (satisfiedTimeRange == null) {
       long startTime = Long.MAX_VALUE;
       long endTime = Long.MIN_VALUE;
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/QueryDataSource.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/QueryDataSource.java
index 10f843c8173..28164934016 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/QueryDataSource.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/read/QueryDataSource.java
@@ -100,6 +100,11 @@ public class QueryDataSource implements IQueryDataSource {
     return unseqResources;
   }
 
+  public boolean isEmpty() {
+    return (seqResources == null || seqResources.isEmpty())
+        && (unseqResources == null || unseqResources.isEmpty());
+  }
+
   @Override
   public IQueryDataSource clone() {
     QueryDataSource queryDataSource =

Reply via email to