You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2019/03/10 07:41:41 UTC
[GitHub] [incubator-druid] KazuhitoT opened a new pull request #7224: Add
ROUND function in druid-sql.
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:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org