cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Benjamin Lerer (JIRA)" <>
Subject [jira] [Commented] (CASSANDRA-12417) Built-in AVG aggregate is much less useful than it should be
Date Tue, 04 Oct 2016 13:51:21 GMT


Benjamin Lerer commented on CASSANDRA-12417:

If my understanding is right, both functions (sum and avg) can end up returning different
results, even in normal situation, due to the fact that both use now the Kahan's algorithm.
The way overflow is handled is also not the same.
I do not deny that overall it is much better but it is clearly a change of behaviour, which
is why I would have prefered that the change goes only in 3.X.
Now, it is true that it might also not be a problem for anybody, so feel free to do as you

> Built-in AVG aggregate is much less useful than it should be
> ------------------------------------------------------------
>                 Key: CASSANDRA-12417
>                 URL:
>             Project: Cassandra
>          Issue Type: Bug
>          Components: CQL
>            Reporter: Branimir Lambov
>            Assignee: Alex Petrov
> For fixed-size integer types overflow is all but guaranteed to happen, yielding incorrect
result. While for sum it is somewhat acceptable as the result cannot fit the type, this is
not the case for average.
> As the result of average is always within the scope of the source type, failing to produce
it only signifies a bad implementation. Yes, one can solve this by type-casting, but do we
really want to always have to be telling people that the correct spelling of the average function
is {{cast(avg(cast(value as bigint))) as int)}}, especially if this is so trivial to fix?
> Additionally, the straightforward addition we use for floating point versions is not
a good choice numerically for larger numbers of values. We should switch to a more stable
version, e.g. iterative mean using {{avg = avg + (value - avg) / count}}.

This message was sent by Atlassian JIRA

View raw message