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

jt2594838 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 892dbd85bab Fix floating-point sentinel misuse in KDTree and SDT 
(#18302)
892dbd85bab is described below

commit 892dbd85bab4d665b4873b1e354f36e22d5e033a
Author: Caideyipi <[email protected]>
AuthorDate: Mon Jul 27 11:12:39 2026 +0800

    Fix floating-point sentinel misuse in KDTree and SDT (#18302)
    
    * Fix floating-point sentinel misuse
    
    * Fix master repair integration test expectations
---
 .../apache/iotdb/itbase/constant/TestConstant.java |  2 +-
 .../db/it/udf/IoTDBUDTFBuiltinFunctionIT.java      |  4 +-
 .../sdt/SwingingDoorTrendingFilter.java            |  8 ++--
 .../sdt/SwingingDoorTrendingFilterTest.java        | 17 ++++++++
 .../apache/iotdb/commons/udf/utils/KDTreeUtil.java | 10 ++---
 .../iotdb/commons/udf/utils/KDTreeUtilTest.java    | 49 ++++++++++++++++++++++
 6 files changed, 78 insertions(+), 12 deletions(-)

diff --git 
a/integration-test/src/main/java/org/apache/iotdb/itbase/constant/TestConstant.java
 
b/integration-test/src/main/java/org/apache/iotdb/itbase/constant/TestConstant.java
index 0c9971b1bc4..6e0e818ab10 100644
--- 
a/integration-test/src/main/java/org/apache/iotdb/itbase/constant/TestConstant.java
+++ 
b/integration-test/src/main/java/org/apache/iotdb/itbase/constant/TestConstant.java
@@ -56,7 +56,7 @@ public class TestConstant {
   public static final String DATA_TYPE_STR = ColumnHeaderConstant.DATATYPE;
   public static final String FUNCTION_TYPE_NATIVE = "native";
   public static final double DELTA = 1e-6;
-  public static final double NULL = Double.MIN_VALUE;
+  public static final double NULL = Double.NaN;
 
   public static String[] createSql =
       new String[] {
diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/udf/IoTDBUDTFBuiltinFunctionIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/db/it/udf/IoTDBUDTFBuiltinFunctionIT.java
index 4bec71586cc..fc72bfc6ada 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/db/it/udf/IoTDBUDTFBuiltinFunctionIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/db/it/udf/IoTDBUDTFBuiltinFunctionIT.java
@@ -2012,7 +2012,7 @@ public class IoTDBUDTFBuiltinFunctionIT {
       }
 
       // test 4
-      double[] r4 = {1704.0, 1702.0, 1702.0, 1701.0, 1703.0, 1704.0, 1705.0, 
1706.0};
+      double[] r4 = {1704.0, 1702.0, 1702.0, 1701.0, 1703.0, 1702.0, 1705.0, 
1706.0};
       try (ResultSet resultSet =
           statement.executeQuery(
               "select 
master_repair(s1,s2,s3,m1,m2,m3,'omega'='2','eta'='3.0','k'='5') from 
root.testMasterRepair.d1")) {
@@ -2032,7 +2032,7 @@ public class IoTDBUDTFBuiltinFunctionIT {
       }
 
       // test 5
-      double[] r5 = {1154.55, 1152.30, 1148.65, 1145.20, 1150.55, 1151.55, 
1153.55, 1152.30};
+      double[] r5 = {1154.55, 1152.30, 1148.65, 1145.20, 1150.55, 1152.30, 
1153.55, 1152.30};
       try (ResultSet resultSet =
           statement.executeQuery(
               "select 
master_repair(s1,s2,s3,m1,m2,m3,'omega'='2','eta'='3.0','k'='5','output_column'='2')
 from root.testMasterRepair.d1")) {
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/processor/downsampling/sdt/SwingingDoorTrendingFilter.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/processor/downsampling/sdt/SwingingDoorTrendingFilter.java
index bfc0bc5d3f7..138da2b1a57 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/processor/downsampling/sdt/SwingingDoorTrendingFilter.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/processor/downsampling/sdt/SwingingDoorTrendingFilter.java
@@ -65,8 +65,8 @@ public class SwingingDoorTrendingFilter<T> {
   }
 
   private void init(final long firstTimestamp, final T firstValue) {
-    upperDoor = Double.MIN_VALUE;
-    lowerDoor = Double.MAX_VALUE;
+    upperDoor = Double.NEGATIVE_INFINITY;
+    lowerDoor = Double.POSITIVE_INFINITY;
 
     lastReadTimestamp = firstTimestamp;
     lastReadValue = firstValue;
@@ -158,8 +158,8 @@ public class SwingingDoorTrendingFilter<T> {
   }
 
   private void reset(final long timestamp, final T value) {
-    upperDoor = Double.MIN_VALUE;
-    lowerDoor = Double.MAX_VALUE;
+    upperDoor = Double.NEGATIVE_INFINITY;
+    lowerDoor = Double.POSITIVE_INFINITY;
 
     lastStoredTimestamp = timestamp;
     lastStoredValue = value;
diff --git 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/processor/downsampling/sdt/SwingingDoorTrendingFilterTest.java
 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/processor/downsampling/sdt/SwingingDoorTrendingFilterTest.java
index cd04df04194..67a405eb243 100644
--- 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/processor/downsampling/sdt/SwingingDoorTrendingFilterTest.java
+++ 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/pipe/processor/downsampling/sdt/SwingingDoorTrendingFilterTest.java
@@ -34,6 +34,23 @@ public class SwingingDoorTrendingFilterTest {
     Assert.assertTrue(filter.filter(Long.MAX_VALUE, 0));
   }
 
+  @Test
+  public void testDecreasingTrendIsCompressed() throws Exception {
+    final SwingingDoorTrendingFilter<Integer> filter =
+        new SwingingDoorTrendingFilter<>(createProcessor(0, Long.MAX_VALUE, 
0), 0, 10);
+
+    Assert.assertFalse(filter.filter(1, 9));
+  }
+
+  @Test
+  public void testDecreasingTrendIsCompressedAfterReset() throws Exception {
+    final SwingingDoorTrendingFilter<Integer> filter =
+        new SwingingDoorTrendingFilter<>(createProcessor(0, 10, 0), 0, 20);
+
+    Assert.assertTrue(filter.filter(10, 10));
+    Assert.assertFalse(filter.filter(11, 9));
+  }
+
   private SwingingDoorTrendingSamplingProcessor createProcessor(
       final long compressionMinTimeInterval,
       final long compressionMaxTimeInterval,
diff --git 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/udf/utils/KDTreeUtil.java
 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/udf/utils/KDTreeUtil.java
index 25bf56f4782..7372428e137 100644
--- 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/udf/utils/KDTreeUtil.java
+++ 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/udf/utils/KDTreeUtil.java
@@ -270,13 +270,13 @@ public class KDTreeUtil {
       ArrayList<Double> min_v = new ArrayList<>();
       ArrayList<Double> max_v = new ArrayList<>();
       for (int i = 0; i < dimensions; i++) {
-        double min_temp = Double.MAX_VALUE;
-        double max_temp = Double.MIN_VALUE;
-        for (int j = 1; j < data.size(); j++) {
-          ArrayList<Double> d = data.get(j);
+        double min_temp = Double.POSITIVE_INFINITY;
+        double max_temp = Double.NEGATIVE_INFINITY;
+        for (ArrayList<Double> d : data) {
           if (d.get(i) < min_temp) {
             min_temp = d.get(i);
-          } else if (d.get(i) > max_temp) {
+          }
+          if (d.get(i) > max_temp) {
             max_temp = d.get(i);
           }
         }
diff --git 
a/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/udf/utils/KDTreeUtilTest.java
 
b/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/udf/utils/KDTreeUtilTest.java
new file mode 100644
index 00000000000..73434114cc9
--- /dev/null
+++ 
b/iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/udf/utils/KDTreeUtilTest.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.commons.udf.utils;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+public class KDTreeUtilTest {
+
+  @Test
+  public void testQueryUsesCompleteNodeBounds() {
+    ArrayList<ArrayList<Double>> data = new ArrayList<>();
+    data.add(point(4, 0));
+    data.add(point(-2, -2));
+    data.add(point(-5, 5));
+    data.add(point(1, -1));
+    data.add(point(-4, 5));
+    data.add(point(5, -5));
+    data.add(point(-5, 0));
+
+    KDTreeUtil tree = KDTreeUtil.build(data, 2);
+
+    Assert.assertEquals(point(5, -5), tree.query(point(0.25, -8.75), new 
double[] {1, 1}));
+  }
+
+  private ArrayList<Double> point(double first, double second) {
+    return new ArrayList<>(Arrays.asList(first, second));
+  }
+}

Reply via email to