JackieTien97 commented on code in PR #19305:
URL: https://github.com/apache/iotdb/pull/19305#discussion_r4627850332


##########
library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFMvAvg.java:
##########
@@ -36,6 +36,7 @@ public class UDTFMvAvg implements UDTF {
   int windowSize;
   Type dataType;
   DoubleCircularQueue v;
+  double windowSum = 0.0d;

Review Comment:
   A single running `double` sum can carry an error into later windows. With 
`window=2` and inputs `[2^53, 1, 0, 0, 0]`, both `[0, 0]` windows produce 
`-0.5`. Adding `1` to `2^53` loses the unit to rounding, and evicting `1` still 
subtracts it. Overflow also persists. With `[Double.MAX_VALUE, 
Double.MAX_VALUE, 1, 1]`, the final `[1, 1]` window produces `Infinity`. Please 
use an accumulation strategy that handles both loss of precision and overflow, 
and cover both sequences in `UDTFMvAvgTest`.



##########
iotdb-core/calc-commons/src/main/java/org/apache/iotdb/calc/execution/operator/process/gapfill/AbstractGapFillOperator.java:
##########
@@ -224,7 +224,9 @@ public boolean hasNext() throws Exception {
   }
 
   private boolean hasRemainingGapInPreviousGroup() {
-    return lastGroupKey != null && currentTime < endTime;
+    // endTime is an inclusive bound (see fillGaps and the group-switch flush 
above), so a gap
+    // row at exactly endTime still needs to be emitted
+    return lastGroupKey != null && currentTime <= endTime;

Review Comment:
   This predicate stays true after the final bucket has been emitted when 
`endTime` is `Long.MAX_VALUE`. `nextDateBin()` saturates at that timestamp. The 
no-progress check in `fillGaps()` exits the current call, but `lastGroupKey` 
remains set, so the next call emits the same bucket again and `isFinished()` 
stays false. Please track when the endpoint has been consumed for the current 
group, including when a real row supplies it, and reset that state on a group 
change. A regression test should assert that the endpoint appears exactly once 
and the operator finishes.



##########
library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDTFHistogram.java:
##########
@@ -74,11 +75,37 @@ public void beforeStart(UDFParameters parameters, 
UDTFConfigurations configurati
   public void transform(Row row, PointCollector collector) throws Exception {
     double value = Util.getValueAsDouble(row);
     if (Double.isFinite(value)) {
-      int id = Math.min(Math.max((int) Math.floor((value - start) / gap), 0), 
count - 1);
-      bucket[id]++;
+      bucket[bucketId(value)]++;
     }
   }
 
+  /**
+   * Locate the bucket the given value belongs to. When (end - start) does not 
overflow, the
+   * original uniform binning is kept. When it overflows to +/-Infinity (e.g. 
the default min/max
+   * range), both (value - start) and the bucket width lose their meaning in 
double arithmetic, so a
+   * numerically stable relative position derived from the interval center is 
used instead; this
+   * keeps the mapping monotonic and every bucket reachable.
+   */
+  private int bucketId(double value) {
+    if (!Double.isInfinite(gap)) {
+      return Math.min(Math.max((int) Math.floor((value - start) / gap), 0), 
count - 1);
+    }
+    double center = start / 2 + end / 2;
+    double halfSpan = end / 2 - start / 2;
+    if (!(halfSpan > 0)) {
+      // degenerate range (start == end); mirror the old clamping behavior
+      return value <= start ? 0 : count - 1;
+    }
+    double position = 0.5 + 0.5 * ((value - center) / halfSpan);

Review Comment:
   With the default bounds and `count=2`, zero is the boundary between the two 
buckets. For inputs `[-1, 0, 1]`, I get counts `[0, 3]`. The expected counts 
are `[1, 2]`. For `-1`, adding the tiny negative offset to `0.5` rounds back to 
`0.5`, placing it in the upper bucket alongside zero. Please preserve which 
side of the boundary the input falls on and add this case to 
`UDTFHistogramTest`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to