gianm commented on a change in pull request #7224: Add ROUND function in 
druid-sql.
URL: https://github.com/apache/incubator-druid/pull/7224#discussion_r275167065
 
 

 ##########
 File path: core/src/main/java/org/apache/druid/math/expr/Function.java
 ##########
 @@ -508,9 +510,42 @@ public String name()
     }
 
     @Override
-    protected ExprEval eval(double param)
+    public ExprEval apply(List<Expr> args, Expr.ObjectBinding bindings)
+    {
+      if (args.size() != 1 && args.size() != 2) {
+        throw new IAE("Function[%s] needs 1 or 2 arguments", name());
+      }
+
+      ExprEval value1 = args.get(0).eval(bindings);
+      if (value1.type() != ExprType.LONG && value1.type() != ExprType.DOUBLE) {
+        throw new IAE("The first argument to the function[%s] should be 
integer or double type but get the %s type", name(), value1.type());
+      }
+
+      if (args.size() == 1) {
+        return eval(value1);
+      } else {
+        ExprEval value2 = args.get(1).eval(bindings);
+        if (value2.type() != ExprType.LONG) {
+          throw new IAE("The second argument to the function[%s] should be 
integer type but get the %s type", name(), value2.type());
+        }
+        return eval(value1, value2.asInt());
+      }
+    }
+
+    protected ExprEval eval(ExprEval param)
+    {
+      return eval(param, 0);
+    }
+
+    protected ExprEval eval(ExprEval param, int scale)
 
 Review comment:
   Could probably be private instead of protected, which if so, would be 
preferred.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to