You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2024/11/28 11:50:12 UTC

(iotdb) branch master updated: Fix that queries may retrieve false positive deletion

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 8c6bd8e6c15 Fix that queries may retrieve false positive deletion
8c6bd8e6c15 is described below

commit 8c6bd8e6c15e2a7ce4402124d87a0f82245c5310
Author: Jiang Tian <jt...@163.com>
AuthorDate: Thu Nov 28 19:50:06 2024 +0800

    Fix that queries may retrieve false positive deletion
---
 .../relational/it/db/it/IoTDBDeletionTableIT.java  | 36 ++++++++++++++++++++--
 .../execution/fragment/QueryContext.java           | 15 +++++++--
 2 files changed, 46 insertions(+), 5 deletions(-)

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 3dd9672187b..7c3c3ceab1c 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
@@ -604,20 +604,50 @@ public class IoTDBDeletionTableIT {
       statement.execute("flush");
 
       statement.execute("delete from t" + testNum + " where id1 is NULL and time <= 1");
-      try (ResultSet set = statement.executeQuery("SELECT * FROM t" + testNum)) {
+      try (ResultSet set = statement.executeQuery("SELECT * FROM t" + testNum + " order by time")) {
         assertTrue(set.next());
+        assertEquals(2, set.getLong("time"));
         assertTrue(set.next());
+        assertEquals(3, set.getLong("time"));
         assertFalse(set.next());
       }
 
       statement.execute("delete from t" + testNum + " where id2 is NULL");
-      try (ResultSet set = statement.executeQuery("SELECT * FROM t" + testNum)) {
+      try (ResultSet set = statement.executeQuery("SELECT * FROM t" + testNum + " order by time")) {
         assertTrue(set.next());
+        assertEquals(2, set.getLong("time"));
         assertFalse(set.next());
       }
 
       statement.execute("delete from t" + testNum);
-      try (ResultSet set = statement.executeQuery("SELECT * FROM t" + testNum)) {
+      try (ResultSet set = statement.executeQuery("SELECT * FROM t" + testNum + " order by time")) {
+        assertFalse(set.next());
+      }
+
+      statement.execute("drop table t" + testNum);
+    }
+  }
+
+  @Test
+  public void testEmptyString() throws SQLException {
+    int testNum = 15;
+    try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
+        Statement statement = connection.createStatement()) {
+      statement.execute("use test");
+      statement.execute(
+          "create table t" + testNum + " (id1 string id, id2 string id, s1 int32 measurement)");
+      // id1 is null for this record
+      statement.execute("insert into t" + testNum + " (time, id2, s1) values (1, '1', 1)");
+      statement.execute("insert into t" + testNum + " (time, id2, s1) values (2, '', 2)");
+      statement.execute("insert into t" + testNum + " (time, id2, s1) values (3, NULL, 3)");
+      statement.execute("flush");
+
+      statement.execute("delete from t" + testNum + " where id2 = ''");
+      try (ResultSet set = statement.executeQuery("SELECT * FROM t" + testNum + " order by time")) {
+        assertTrue(set.next());
+        assertEquals(1, set.getLong("time"));
+        assertTrue(set.next());
+        assertEquals(3, set.getLong("time"));
         assertFalse(set.next());
       }
 
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/fragment/QueryContext.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/fragment/QueryContext.java
index 28d4e14703b..566e998d2c4 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/fragment/QueryContext.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/fragment/QueryContext.java
@@ -40,6 +40,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.stream.Collectors;
 
 /** QueryContext contains the shared information with in a query. */
 public class QueryContext {
@@ -117,8 +118,18 @@ public class QueryContext {
       return Collections.emptyList();
     }
 
-    return ModificationUtils.sortAndMerge(
-        getAllModifications(tsFileResource).getOverlapped(deviceID, measurement));
+    List<ModEntry> modEntries =
+        ModificationUtils.sortAndMerge(
+            getAllModifications(tsFileResource).getOverlapped(deviceID, measurement));
+    if (deviceID.isTableModel()) {
+      // the pattern tree has false-positive for table model deletion, so we do a further
+      //     filtering
+      modEntries =
+          modEntries.stream()
+              .filter(mod -> mod.affects(deviceID) && mod.affects(measurement))
+              .collect(Collectors.toList());
+    }
+    return modEntries;
   }
 
   public List<ModEntry> getPathModifications(TsFileResource tsFileResource, IDeviceID deviceID)