[
https://issues.apache.org/jira/browse/DRILL-8376?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17656137#comment-17656137
]
ASF GitHub Bot commented on DRILL-8376:
---------------------------------------
cgivre commented on code in PR #2729:
URL: https://github.com/apache/drill/pull/2729#discussion_r1064724101
##########
contrib/udfs/src/main/java/org/apache/drill/exec/udfs/DistributionFunctions.java:
##########
@@ -0,0 +1,335 @@
+/*
+ * 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.drill.exec.udfs;
+
+import org.apache.drill.exec.expr.DrillAggFunc;
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.FunctionScope;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate.NullHandling;
+import org.apache.drill.exec.expr.annotations.Output;
+import org.apache.drill.exec.expr.annotations.Param;
+import org.apache.drill.exec.expr.annotations.Workspace;
+import org.apache.drill.exec.expr.holders.Float8Holder;
+import org.apache.drill.exec.expr.holders.IntHolder;
+
+public class DistributionFunctions {
+
+ @FunctionTemplate(names = {"width_bucket", "widthBucket"},
+ scope = FunctionScope.SIMPLE,
+ nulls = NullHandling.NULL_IF_NULL)
+ public static class WidthBucketFunction implements DrillSimpleFunc {
+
+ @Param
+ Float8Holder inputValue;
+
+ @Param
+ Float8Holder MinRangeValueHolder;
+
+ @Param
+ Float8Holder MaxRangeValueHolder;
+
+ @Param
+ IntHolder bucketCountHolder;
+
+ @Workspace
+ double binWidth;
+
+ @Output
+ IntHolder bucket;
+
+ @Override
+ public void setup() {
+ double max = MaxRangeValueHolder.value;
+ double min = MinRangeValueHolder.value;
+ int 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);
+ }
+ }
+ }
+ }
+
+ @FunctionTemplate(
+ names = {"kendall_correlation","kendallCorrelation", "kendallTau",
"kendall_tau"},
+ scope = FunctionScope.POINT_AGGREGATE,
+ nulls = NullHandling.INTERNAL
+ )
+ public static class KendallTauFunction implements DrillAggFunc {
+ @Param
+ Float8Holder xInput;
+
+ @Param
+ Float8Holder yInput;
+
+ @Workspace
+ Float8Holder prevXValue;
+
+ @Workspace
+ Float8Holder prevYValue;
+
+ @Workspace
+ IntHolder concordantPairs;
+
+ @Workspace
+ IntHolder discordantPairs;
+
+ @Workspace
+ IntHolder n;
+
+ @Output
+ Float8Holder tau;
+
+ @Override
+ public void add() {
+ double xValue = xInput.value;
+ double yValue = yInput.value;
+
+ if (n.value > 0) {
+ if ((xValue > prevXValue.value && yValue > prevYValue.value) ||
(xValue < prevXValue.value && yValue < prevYValue.value)) {
+ concordantPairs.value = concordantPairs.value + 1;
+ } else if ((xValue > prevXValue.value && yValue < prevYValue.value) ||
(xValue < prevXValue.value && yValue > prevYValue.value)) {
+ discordantPairs.value = discordantPairs.value + 1;
+ } else {
+ //Tie...
+ }
+
+ prevXValue.value = xInput.value;
+ prevYValue.value = yInput.value;
+ n.value = n.value + 1;
Review Comment:
Fixed.
> Add Distribution UDFs
> ---------------------
>
> Key: DRILL-8376
> URL: https://issues.apache.org/jira/browse/DRILL-8376
> Project: Apache Drill
> Issue Type: Improvement
> Components: Functions - Drill
> Affects Versions: 1.21
> Reporter: Charles Givre
> Assignee: Charles Givre
> Priority: Minor
>
> Add `width_bucket`, `pearson_correlation` and `kendall_correlation` to Drill
--
This message was sent by Atlassian Jira
(v8.20.10#820010)