From d73a0a3dc6bd13646a6a526c9fb4f231b90d7d32 Mon Sep 17 00:00:00 2001 From: Caideyipi <87789683+Caideyipi@users.noreply.github.com> Date: Fri, 24 Jul 2026 17:27:23 +0800 Subject: [PATCH 1/2] Fix floating-point sentinel misuse --- .../iotdb/itbase/constant/TestConstant.java | 2 +- .../sdt/SwingingDoorTrendingFilter.java | 8 +-- .../sdt/SwingingDoorTrendingFilterTest.java | 17 +++++++ .../iotdb/commons/udf/utils/KDTreeUtil.java | 10 ++-- .../commons/udf/utils/KDTreeUtilTest.java | 49 +++++++++++++++++++ 5 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/udf/utils/KDTreeUtilTest.java 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 0c9971b1bc49c..6e0e818ab10cd 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/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 bfc0bc5d3f791..138da2b1a575d 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 SwingingDoorTrendingFilter( } 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 @@ private boolean isTimeDistanceGreaterThanOrEqual( } 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 cd04df0419498..67a405eb24334 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 void testExtremeTimestampDistanceReachesMaxInterval() throws Exception { Assert.assertTrue(filter.filter(Long.MAX_VALUE, 0)); } + @Test + public void testDecreasingTrendIsCompressed() throws Exception { + final SwingingDoorTrendingFilter 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 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 25bf56f4782c0..7372428e13746 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 @@ static ArrayList> maxMin(ArrayList> data, in ArrayList min_v = new ArrayList<>(); ArrayList 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 d = data.get(j); + double min_temp = Double.POSITIVE_INFINITY; + double max_temp = Double.NEGATIVE_INFINITY; + for (ArrayList 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 0000000000000..73434114cc902 --- /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> 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 point(double first, double second) { + return new ArrayList<>(Arrays.asList(first, second)); + } +} From 3647683757b1e5471a3d6691980eeee832521d15 Mon Sep 17 00:00:00 2001 From: Caideyipi <87789683+Caideyipi@users.noreply.github.com> Date: Fri, 24 Jul 2026 18:45:20 +0800 Subject: [PATCH 2/2] Fix master repair integration test expectations --- .../apache/iotdb/db/it/udf/IoTDBUDTFBuiltinFunctionIT.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 4bec71586cc31..fc72bfc6ada5f 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 void testMasterRepair() { } // 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 void testMasterRepair() { } // 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")) {