KazuhitoT opened a new pull request #7224: Add ROUND function in druid-sql.
URL: https://github.com/apache/incubator-druid/pull/7224
 
 
   Add `ROUND` function in druid-sql.
   issue: https://github.com/apache/incubator-druid/issues/5644
   
   - It can be used for doubles (return `double`) and integers (return `long`).
   - Both `ROUND(x)` and `ROUND(x, y)` works like `TRUNC(x, y)`.
   - This is implemented by replacing `Math.round()` with 
`Bigdecimal.setScale()` as following:
   ```java
   protected ExprEval eval(ExprEval param, ExprEval scale)
   {
     if (param.type() == ExprType.LONG) {
       Long value = BigDecimal.valueOf(param.asLong()).setScale(scale.asInt(), 
RoundingMode.HALF_UP).longValue();
       return ExprEval.of(value);
     } else {
       double value = 
BigDecimal.valueOf(param.asDouble()).setScale(scale.asInt(), 
RoundingMode.HALF_UP).doubleValue();
       return ExprEval.of(value);
     }
   }
   ```

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