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

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


The following commit(s) were added to refs/heads/master by this push:
     new b0495da2d6a fix last query bug #17073
b0495da2d6a is described below

commit b0495da2d6a5d3a21e3e7500aa9e5f504ec57d20
Author: shuwenwei <[email protected]>
AuthorDate: Mon Jan 26 10:12:52 2026 +0800

    fix last query bug #17073
---
 .../db/it/last/IoTDBLastQueryLastCacheIT.java      | 42 ++++++++++++++++++++++
 .../operator/process/last/LastQueryOperator.java   |  6 ++--
 2 files changed, 44 insertions(+), 4 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/last/IoTDBLastQueryLastCacheIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/db/it/last/IoTDBLastQueryLastCacheIT.java
index 1c69857a3c5..3eedf1540eb 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/db/it/last/IoTDBLastQueryLastCacheIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/db/it/last/IoTDBLastQueryLastCacheIT.java
@@ -192,4 +192,46 @@ public class IoTDBLastQueryLastCacheIT {
         };
     resultSetEqualTest("select last s1 from root.sg.d1;", expectedHeader, 
retArray);
   }
+
+  @Test
+  public void testNonAlignedLastQueryWithTimeFilterWithoutCache() throws 
SQLException {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute("insert into root.db1.g1.d3(time,s_3) values (1,1)");
+      statement.execute("insert into root.db1.g1.d3(time,s_3) values (2,2)");
+      statement.execute("insert into root.db1.g1.d3(time,s_3) values (3,3)");
+      statement.execute("insert into root.db1.g1.d3(time,s_3) values (4,4)");
+      statement.execute("insert into root.db1.g1.d3(time,s_1) values (1,1)");
+      statement.execute("insert into root.db1.g1.d3(time,s_1) values (2,2)");
+    }
+    String[] expectedHeader =
+        new String[] {TIMESTAMP_STR, TIMESERIES_STR, VALUE_STR, DATA_TYPE_STR};
+    String[] retArray =
+        new String[] {
+          "4,root.db1.g1.d3.s_3,4.0,DOUBLE,",
+        };
+    resultSetEqualTest(
+        "select last s_1, s_3 from root.db1.g1.d3 where time > 2;", 
expectedHeader, retArray);
+  }
+
+  @Test
+  public void testAlignedLastQueryWithTimeFilterWithoutCache() throws 
SQLException {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute("insert into root.db1.g1.d4(time,s_3) aligned values 
(1,1)");
+      statement.execute("insert into root.db1.g1.d4(time,s_3) aligned values 
(2,2)");
+      statement.execute("insert into root.db1.g1.d4(time,s_3) aligned values 
(3,3)");
+      statement.execute("insert into root.db1.g1.d4(time,s_3) aligned values 
(4,4)");
+      statement.execute("insert into root.db1.g1.d4(time,s_1) aligned values 
(1,1)");
+      statement.execute("insert into root.db1.g1.d4(time,s_1) aligned values 
(2,2)");
+    }
+    String[] expectedHeader =
+        new String[] {TIMESTAMP_STR, TIMESERIES_STR, VALUE_STR, DATA_TYPE_STR};
+    String[] retArray =
+        new String[] {
+          "4,root.db1.g1.d4.s_3,4.0,DOUBLE,",
+        };
+    resultSetEqualTest(
+        "select last s_1, s_3 from root.db1.g1.d4 where time > 2;", 
expectedHeader, retArray);
+  }
 }
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/last/LastQueryOperator.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/last/LastQueryOperator.java
index dd41bbd7afa..d2389a00898 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/last/LastQueryOperator.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/last/LastQueryOperator.java
@@ -112,12 +112,10 @@ public class LastQueryOperator implements ProcessOperator 
{
         && !tsBlockBuilder.isFull()) {
       if (children.get(currentIndex).hasNextWithTimer()) {
         TsBlock tsBlock = children.get(currentIndex).nextWithTimer();
-        if (tsBlock == null) {
-          return null;
-        } else if (!tsBlock.isEmpty()) {
+        if (tsBlock != null && !tsBlock.isEmpty()) {
           LastQueryUtil.appendLastValue(tsBlockBuilder, tsBlock);
-          return null;
         }
+        return null;
       } else {
         children.get(currentIndex).close();
         children.set(currentIndex, null);

Reply via email to