This is an automated email from the ASF dual-hosted git repository. leirui pushed a commit to branch research/LTS-visualization in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit b7b4154f0a4534db121a7ee28f80a6746f14986a Author: Lei Rui <[email protected]> AuthorDate: Mon Oct 7 01:44:06 2024 +0800 add --- .../iotdb/db/query/udf/builtin/UDTFM4MAC.java | 20 ++++++++-------- .../iotdb/db/query/udf/builtin/UDTFMinMax.java | 27 +++++++++++----------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/server/src/main/java/org/apache/iotdb/db/query/udf/builtin/UDTFM4MAC.java b/server/src/main/java/org/apache/iotdb/db/query/udf/builtin/UDTFM4MAC.java index 800807d334c..bd1b70218c4 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/udf/builtin/UDTFM4MAC.java +++ b/server/src/main/java/org/apache/iotdb/db/query/udf/builtin/UDTFM4MAC.java @@ -33,6 +33,7 @@ import org.apache.iotdb.tsfile.read.common.IOMonitor2; import org.apache.iotdb.tsfile.read.common.IOMonitor2.DataSetType; import java.io.IOException; +import java.util.Arrays; // This is the UDFM4 in paper. // The integration test for MAC is in org.apache.iotdb.db.integration.m4.MyTest3.test1_2 @@ -127,11 +128,10 @@ public class UDTFM4MAC implements UDTF { .setOutputDataType(TSDataType.TEXT); init(); this.idx = -1; - result = new String[w]; - for (int i = 0; i < w; i++) { - result[i] = "empty"; - } - // System.out.println("====DEBUG====: use UDTFM4MAC for MAC"); + long len = (tqe - tqs) / w; // floor + int num = (int) Math.ceil((tqe - tqs) * 1.0 / len); // ceil + result = new String[num]; + Arrays.fill(result, "empty"); } @Override @@ -161,7 +161,7 @@ public class UDTFM4MAC implements UDTF { protected void transformInt(long time, int value) throws IOException { long intervalLen = (tqe - tqs) / w; // consistent with MinMaxCache's strategy int pos = (int) Math.floor((time - tqs) * 1.0 / intervalLen); - if (pos >= w) { + if (pos < 0 || pos > result.length) { throw new IOException("Make sure the range time filter is time>=tqs and time<tqe"); } @@ -213,7 +213,7 @@ public class UDTFM4MAC implements UDTF { long intervalLen = (tqe - tqs) / w; // consistent with MinMaxCache's strategy int pos = (int) Math.floor((time - tqs) * 1.0 / intervalLen); - if (pos >= w) { + if (pos < 0 || pos > result.length) { throw new IOException("Make sure the range time filter is time>=tqs and time<tqe"); } @@ -264,7 +264,7 @@ public class UDTFM4MAC implements UDTF { long intervalLen = (tqe - tqs) / w; // consistent with MinMaxCache's strategy int pos = (int) Math.floor((time - tqs) * 1.0 / intervalLen); - if (pos >= w) { + if (pos < 0 || pos > result.length) { throw new IOException("Make sure the range time filter is time>=tqs and time<tqe"); } @@ -315,7 +315,7 @@ public class UDTFM4MAC implements UDTF { long intervalLen = (tqe - tqs) / w; // consistent with MinMaxCache's strategy int pos = (int) Math.floor((time - tqs) * 1.0 / intervalLen); - if (pos >= w) { + if (pos < 0 || pos > result.length) { throw new IOException("Make sure the range time filter is time>=tqs and time<tqe"); } @@ -464,7 +464,7 @@ public class UDTFM4MAC implements UDTF { } } // collect result - for (int i = 0; i < w; i++) { + for (int i = 0; i < result.length; i++) { // long startInterval = tqs + (tqe - tqs) / w * i; long startInterval = i; collector.putString(startInterval, result[i]); diff --git a/server/src/main/java/org/apache/iotdb/db/query/udf/builtin/UDTFMinMax.java b/server/src/main/java/org/apache/iotdb/db/query/udf/builtin/UDTFMinMax.java index be5b1b3ca94..91a86ddb16a 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/udf/builtin/UDTFMinMax.java +++ b/server/src/main/java/org/apache/iotdb/db/query/udf/builtin/UDTFMinMax.java @@ -33,6 +33,7 @@ import org.apache.iotdb.tsfile.read.common.IOMonitor2; import org.apache.iotdb.tsfile.read.common.IOMonitor2.DataSetType; import java.io.IOException; +import java.util.Arrays; public class UDTFMinMax implements UDTF { @@ -99,10 +100,10 @@ public class UDTFMinMax implements UDTF { .setOutputDataType(TSDataType.TEXT); init(); this.idx = -1; - result = new String[w]; - for (int i = 0; i < w; i++) { - result[i] = "empty"; - } + long len = (tqe - tqs) / w; // floor + int num = (int) Math.ceil((tqe - tqs) * 1.0 / len); // ceil + result = new String[num]; + Arrays.fill(result, "empty"); } @Override @@ -130,9 +131,9 @@ public class UDTFMinMax implements UDTF { } protected void transformInt(long time, int value) throws IOException { - double intervalLen = (tqe - tqs) * 1.0 / w; + long intervalLen = (tqe - tqs) / w; // consistent with MinMaxCache's strategy int pos = (int) Math.floor((time - tqs) * 1.0 / intervalLen); - if (pos >= w) { + if (pos < 0 || pos > result.length) { throw new IOException("Make sure the range time filter is time>=tqs and time<tqe"); } @@ -163,10 +164,10 @@ public class UDTFMinMax implements UDTF { } protected void transformLong(long time, long value) throws IOException { - double intervalLen = (tqe - tqs) * 1.0 / w; + long intervalLen = (tqe - tqs) / w; // consistent with MinMaxCache's strategy int pos = (int) Math.floor((time - tqs) * 1.0 / intervalLen); - if (pos >= w) { + if (pos < 0 || pos > result.length) { throw new IOException("Make sure the range time filter is time>=tqs and time<tqe"); } @@ -197,10 +198,10 @@ public class UDTFMinMax implements UDTF { } protected void transformFloat(long time, float value) throws IOException { - double intervalLen = (tqe - tqs) * 1.0 / w; + long intervalLen = (tqe - tqs) / w; // consistent with MinMaxCache's strategy int pos = (int) Math.floor((time - tqs) * 1.0 / intervalLen); - if (pos >= w) { + if (pos < 0 || pos > result.length) { throw new IOException("Make sure the range time filter is time>=tqs and time<tqe"); } @@ -231,10 +232,10 @@ public class UDTFMinMax implements UDTF { } protected void transformDouble(long time, double value) throws IOException { - double intervalLen = (tqe - tqs) * 1.0 / w; + long intervalLen = (tqe - tqs) / w; // consistent with MinMaxCache's strategy int pos = (int) Math.floor((time - tqs) * 1.0 / intervalLen); - if (pos >= w) { + if (pos < 0 || pos > result.length) { throw new IOException("Make sure the range time filter is time>=tqs and time<tqe"); } @@ -326,7 +327,7 @@ public class UDTFMinMax implements UDTF { } } // collect result - for (int i = 0; i < w; i++) { + for (int i = 0; i < result.length; i++) { // long startInterval = tqs + (tqe - tqs) / w * i; long startInterval = i; collector.putString(startInterval, result[i]);
