[
https://issues.apache.org/jira/browse/CASSANDRA-18470?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17714578#comment-17714578
]
Nadav Har'El commented on CASSANDRA-18470:
------------------------------------------
I did a few more experiments and have a better understanding of the bug. The
problem is not just integers vs ".0", but the precision of the inputs:
If I have the values 1.1 and 1.2 and calculate the AVG, it comes out as 1.1
instead of 1.15.
It appears that the situation we have right now is basically that the result of
the division will have exactly as many digits after the decimal point as its
inputs have. It's not clear that this is what users would expect.
Solving this problem is not trivial - it's not clear which precision we should
use for the division. For example, consider averaging 0.0, 0.0 and 1.0. It
should result in 0.3333333. But how many threes? I don't know... Right now
averaging 0, 0, 1 will result in 0, averaging 0.0, 0.0 and 1.0 result in 0.3,
averaging 0.00, 0.00, 1.00 will result in 0.33, and so on.
> Average of "decimal" values rounds the average if all inputs are integers
> -------------------------------------------------------------------------
>
> Key: CASSANDRA-18470
> URL: https://issues.apache.org/jira/browse/CASSANDRA-18470
> Project: Cassandra
> Issue Type: Bug
> Reporter: Nadav Har'El
> Priority: Normal
>
> When running the AVG aggregator on "decimal" values, each value is an
> arbitrary-precision number which may be an integer or fractional, but it is
> expected that the average would be, in general, fractional. But it turns out
> that if all the values are integer *without* a ".0", the aggregator sums them
> up as integers and the final division returns an integer too instead of the
> fractional response expected from a "decimal" value.
> For example:
> # AVG of {{decimal}} values 1.0 and 2.0 returns 1.5, as expected.
> # AVG of 1.0 and 2 or 1 and 2.0 also return 1.5.
> # But AVG of 1 and 2 returns... 1. This is wrong. The user asked for the
> average to be a "decimal", not a "varint", so there is no reason why it
> should be rounded up to be an integer.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]