diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBDeletionTableIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBDeletionTableIT.java index c63a76e09f8c..95eee41d007a 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBDeletionTableIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBDeletionTableIT.java @@ -356,6 +356,28 @@ public void testRangeDelete() throws SQLException { cleanData(4); } + @Test + public void testSuccessfullyInvalidateCache() throws SQLException { + prepareData(4, 1); + try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT); + Statement statement = connection.createStatement()) { + statement.execute("use test"); + statement.executeQuery( + "SELECT last(time), last_by(s0,time), last_by(s1,time), last_by(s2,time), last_by(s3,time), last_by(s4,time) FROM vehicle4 where deviceId = 'd0'"); + + // [1, 400] -> [1, 299] + statement.execute("DELETE FROM vehicle4 WHERE time >= 300"); + try (ResultSet set = statement.executeQuery("SELECT s0 FROM vehicle4")) { + int cnt = 0; + while (set.next()) { + cnt++; + } + assertEquals(299, cnt); + } + } + cleanData(4); + } + @Test public void testFullDeleteWithoutWhereClause() throws SQLException { prepareData(5, 1); diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/cache/TableDeviceLastCache.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/cache/TableDeviceLastCache.java index 3f3c1d2a0532..5bf819709872 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/cache/TableDeviceLastCache.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/cache/TableDeviceLastCache.java @@ -160,7 +160,7 @@ int tryUpdate( "", (time, tvPair) -> tvPair.getTimestamp() < finalLastTime - ? new TimeValuePair(finalLastTime, null) + ? new TimeValuePair(finalLastTime, EMPTY_PRIMITIVE_TYPE) : tvPair); return diff.get(); }