Remus,

Thanks for looking into this. You're right that sum() result doesn't
increase the scale, but have you seen that sum UDF returns wrong scale?

As to the implementation of avg UDF, the object inspector for sum field is
initialized with a scale + 4, which might not be necessary, but perhaps
harmless. The same object inspector is also used for the average result,
which gives correct type. I guess it's possible to separate this into two
object inspectors, one for sum field and one for the avg result, but the
difference might be subtle and questionable. This is because the data may
not comply to the metadata specified for Hive tables. Thus, I'm not sure if
truncating data before it's summed if the right behavior.

Do you have a use case that suggests one is better than the other?

--Xuefu


On Fri, Feb 14, 2014 at 3:55 AM, Remus Rusanu <rem...@microsoft.com> wrote:

> Hi,
>
> With HIVE-5872 the intermediate sum field for decimal aggregates was
> changed to increase scale by 4. I understand the reasoning for having
> accurate precision/scale for the aggregate output. However, for the
> intermediate sum field of AVG, I believe we should increase precision w/o
> increasing scale. The sum can grow large, but cannot increase digits in the
> fractional part, so we should increase the precision of the sum, but not
> the scale. When sum is divided by count to get the average on the reduce
> side then we should indeed project value with higher scale.
>
> Opinions?
>
> Thanks,
> ~Remus
>
>

Reply via email to