jnturton commented on code in PR #2729: URL: https://github.com/apache/drill/pull/2729#discussion_r1065424637
########## contrib/udfs/src/main/java/org/apache/drill/exec/udfs/DistributionFunctions.java: ########## @@ -51,31 +51,29 @@ public static class WidthBucketFunction implements DrillSimpleFunc { @Workspace double binWidth; + @Workspace + int bucketCount; + @Output IntHolder bucket; @Override public void setup() { double max = MaxRangeValueHolder.value; double min = MinRangeValueHolder.value; - int bucketCount = bucketCountHolder.value; + bucketCount = bucketCountHolder.value; binWidth = (max - min) / bucketCount; } @Override public void eval() { - // There is probably a more elegant way of doing this... - double binFloor = MinRangeValueHolder.value; - double binCeiling = binFloor + binWidth; - - for (int i = 1; i <= bucketCountHolder.value; i++) { - if (inputValue.value <= binCeiling && inputValue.value > binFloor) { - bucket.value = i; - break; - } else { - binFloor = binCeiling; - binCeiling = binWidth * (i + 1); - } + if (inputValue.value < MinRangeValueHolder.value) { + bucket.value = 0; + } else if (inputValue.value > MaxRangeValueHolder.value) { + bucket.value = bucketCount + 1; + } else { + double f = (1 + (inputValue.value - MinRangeValueHolder.value) / binWidth); Review Comment: It looks like `f` is recomputed rather than used in what follows. -- 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: dev-unsubscr...@drill.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org