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_r265396372
##########
File path: core/src/main/java/org/apache/druid/math/expr/Function.java
##########
@@ -450,9 +452,43 @@ public String name()
}
@Override
- protected ExprEval eval(double param)
+ public ExprEval apply(List<Expr> args, Expr.ObjectBinding bindings)
{
- return ExprEval.of(Math.round(param));
+ if (args.size() == 1) {
+ ExprEval value1 = args.get(0).eval(bindings);
+ if (value1.type() != ExprType.LONG && value1.type() !=
ExprType.DOUBLE) {
+ throw new IAE("first argument should be integer or double type but
got %s type", value1.type());
+ }
+ return eval(value1);
+ } else if (args.size() == 2) {
+ ExprEval value1 = args.get(0).eval(bindings);
+ ExprEval value2 = args.get(1).eval(bindings);
+ if (value1.type() != ExprType.LONG && value1.type() !=
ExprType.DOUBLE) {
+ throw new IAE("first argument should be integer or double type but
got %s type", value1.type());
+ }
+ if (value2.type() != ExprType.LONG) {
+ throw new IAE("second argument should be integer type but got %s
type", value2.type());
+ }
+ return eval(value1, value2.asInt());
+ } else {
+ throw new IAE("Function[%s] needs 1 or 2 arguments", name());
Review comment:
We should check the size at the beginning of the apply method, then we can
refactor the processing logic of `ExprEval value1` to eliminate duplicate code
blocks.
----------------------------------------------------------------
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]