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

 ##########
 File path: core/src/main/java/org/apache/druid/math/expr/Function.java
 ##########
 @@ -441,18 +443,43 @@ protected ExprEval eval(double param)
     }
   }
 
-  class Round extends SingleParamMath
+  class Round implements Function
   {
+    @Override
+    public ExprEval apply(List<Expr> args, Expr.ObjectBinding bindings)
+    {
+      if (args.size() == 1) {
+        Expr expr1 = args.get(0);
+        return eval(expr1.eval(bindings));
+      } else if (args.size() == 2) {
+        Expr expr1 = args.get(0);
+        Expr expr2 = args.get(1);
+        return eval(expr1.eval(bindings), expr2.eval(bindings));
+      } else {
+        throw new IAE("Function[%s] needs 1 or 2 arguments", name());
+      }
+    }
+
     @Override
     public String name()
     {
       return "round";
     }
 
-    @Override
-    protected ExprEval eval(double param)
+    protected ExprEval eval(ExprEval param)
+    {
+      return eval(param, ExprEval.of(0));
+    }
+
+    protected ExprEval eval(ExprEval param, ExprEval scale)
     {
-      return ExprEval.of(Math.round(param));
+      if (param.type() == ExprType.LONG) {
+        Long value = 
BigDecimal.valueOf(param.asLong()).setScale(scale.asInt(), 
RoundingMode.HALF_UP).longValue();
 
 Review comment:
   `Long value` used an unnecessary type boxing here.

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