estherbuchwalter commented on a change in pull request #2461:
URL: https://github.com/apache/drill/pull/2461#discussion_r819100324



##########
File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/MathFunctionsVarcharInput.java
##########
@@ -0,0 +1,569 @@
+/*
+ * 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.expr.fn.impl;
+
+
+import org.apache.drill.exec.expr.DrillSimpleFunc;
+import org.apache.drill.exec.expr.annotations.FunctionTemplate;
+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;
+import org.apache.drill.exec.expr.holders.NullableFloat8Holder;
+import org.apache.drill.exec.expr.holders.NullableVarCharHolder;
+import org.apache.drill.exec.expr.holders.VarCharHolder;
+
+public class MathFunctionsVarcharInput {
+  /*
+  @FunctionTemplate(name = "rand", isRandom = true,
+    scope = FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class RandomWithSeed implements DrillSimpleFunc{
+    @Param
+    VarCharHolder seed;
+    @Workspace
+    java.util.Random rand;
+    @Output  Float8Holder out;
+
+    @Workspace org.apache.drill.exec.expr.fn.impl.MathFunctionsVarcharUtils 
mathUtils;
+
+    public void setup(){
+      mathUtils = new MathFunctionsVarcharUtils();
+    }
+
+    public void eval(){
+      String seedStr = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.getStringFromVarCharHolder(seed);
+      Double seedDbl = mathUtils.validateInput(seedStr);
+
+      if (seedDbl.isNaN()) {
+        out.value = java.lang.Float.NaN;
+      }
+      else {
+        BigInteger seedBigInt = new 
java.math.BigInteger(String.valueOf(seedDbl));
+        rand = new java.util.Random(seedBigInt.intValue());
+        out.value = rand.nextDouble();
+      }
+    }
+  }
+  /*
+    // The preexisting power() method accepts VARCHAR input, but this method 
adds a check for invalid input
+    @FunctionTemplate(name = "power", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+    public static class Power implements DrillSimpleFunc{
+
+      @Param VarCharHolder a;
+      @Param VarCharHolder b;
+      @Output  Float8Holder out;
+
+      @Workspace org.apache.drill.exec.expr.fn.impl.MathFunctionsVarcharUtils 
mathUtils;
+
+      public void setup(){
+        mathUtils = new MathFunctionsVarcharUtils();
+      }
+
+      public void eval(){
+        String aStr = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.getStringFromVarCharHolder(a);
+        Double aDbl = mathUtils.validateInput(aStr);
+
+        String bStr = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.getStringFromVarCharHolder(b);
+        Double bDbl = mathUtils.validateInput(bStr);
+
+        if (aDbl.isNaN() || bDbl.isNaN()) {
+          out.value = java.lang.Float.NaN;
+        }
+        else {
+          out.value = java.lang.Math.pow(aDbl, bDbl);
+        }
+
+        System.out.println("out.value: " + out.value);
+      }
+
+    }
+
+    // The preexisting power() method accepts VARCHAR input, but this method 
adds a check for invalid input
+    @FunctionTemplate(name = "power", scope = 
FunctionTemplate.FunctionScope.SIMPLE, nulls = 
FunctionTemplate.NullHandling.NULL_IF_NULL)
+    public static class Power implements DrillSimpleFunc{
+
+      @Param VarCharHolder a;
+      @Param Float8Holder b;
+      @Output  Float8Holder out;
+
+      @Workspace org.apache.drill.exec.expr.fn.impl.MathFunctionsVarcharUtils 
mathUtils;
+
+      public void setup(){
+        mathUtils = new MathFunctionsVarcharUtils();
+      }
+
+      public void eval(){
+        String aStr = 
org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.getStringFromVarCharHolder(a);
+        Double aDbl = mathUtils.validateInput(aStr);
+
+        if (aDbl.isNaN()) {
+          out.value = java.lang.Float.NaN;
+        }
+        else {
+          out.value = java.lang.Math.pow(aDbl, b);
+        }
+
+        System.out.println("out.value: " + out.value);
+      }
+
+    }
+
+   */
+  @FunctionTemplate(name = "mod",
+    scope = FunctionTemplate.FunctionScope.SIMPLE,
+    nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
+  public static class Mod implements DrillSimpleFunc {
+
+    @Param
+    VarCharHolder a;

Review comment:
       @paul-rogers, thank you for your input. I appreciate your comments and 
thorough explanation. 
   We are thinking about these issues and experimenting to see what would work 
well with Drill and accomplish our goal. 
   
   Please note that this PR is currently marked as `DRAFT` since it is very 
much a WIP. We can request a review when it is ready.




-- 
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