Details

Type: Subtask

Status: Resolved

Priority: Major

Resolution: Fixed

Affects Version/s: Impala 2.8.0

Fix Version/s: Impala 2.9.0

Component/s: Backend

Labels:None

Target Version:
Description
Currently, the result type of AVG() is set to be the same as the input type. Instead, it should be related to the rule for divide of DECIMAL result type, since AVG() is essentially a divide of DECIMAL sum by the integral count. This will require probably some additional plumbing through the UDA interface in addition to the frontend work.
Issue Links
 breaks

IMPALA5251 DecimalAvgFinalize() gets the wrong arg type
 Resolved
 is blocked by

IMPALA4879 FunctionContext::GetArgType() returns wrong type in UDA Merge() and Finalize()
 Resolved
Activity
 All
 Comments
 Work Log
 History
 Activity
 Transitions
https://github.com/apache/incubatorimpala/commit/637cc3e447650a5c9bc4b8dd79ee74fd11459fa2
IMPALA4821: Update AVG() for DECIMAL_V2This change implements the DECIMAL_V2's behavior for AVG().
The differences with DECIMAL_V1 are:
1. The output type has a minimum scale of 6. This is similar
to MS SQL's behavior which takes the max of 6 and the input
type's scale. We deviate from MS SQL in the output's precision
which is always set to 38. We use the smallest precision which
can store the output. A key insight is that the output of AVG()
is no wider than the inputs. Precision only needs to be adjusted
when the scale is augmented. Using a smaller precision avoids
potential loss of precision in subsequent decimal operations
(e.g. division) if AVG() is a subexpression. Please note that
the output type is different from SUM()/COUNT() as the latter
can have a much larger scale.
2. Due to a minimum of 6 decimal places for the output,
AVG() for decimal values whose whole number part exceeds 32
decimal places (e.g. DECIMAL(38,4), DECIMAL(33,0)) will
always overflow as the scale is augmented to 6. Certain
decimal types which work with AVG() in DECIMAL_V1 no longer
work in DECIMAL_V2.
ChangeId: I28f5ef0370938440eb5b1c6d29b2f24e6f88499f
Reviewedon: http://gerrit.cloudera.org:8080/6038
Reviewedby: Dan Hecht <dhecht@cloudera.com>
Reviewedby: Alex Behm <alex.behm@cloudera.com>
Testedby: Impala Public Jenkins