Repository: spark Updated Branches: refs/heads/branch-1.0 91a64eba9 -> f9fdf32c0
[SPARK-1947] [SQL] Child of SumDistinct or Average should be widened to prevent overflows the same as Sum. Child of `SumDistinct` or `Average` should be widened to prevent overflows the same as `Sum`. Author: Takuya UESHIN <[email protected]> Closes #902 from ueshin/issues/SPARK-1947 and squashes the following commits: 99c3dcb [Takuya UESHIN] Insert Cast for SumDistinct and Average. (cherry picked from commit 3ce81494c512bc97979a743ea77ef913315f7fb6) Signed-off-by: Michael Armbrust <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/spark/repo Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/f9fdf32c Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/f9fdf32c Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/f9fdf32c Branch: refs/heads/branch-1.0 Commit: f9fdf32c09f089ccd7a24642294c3ae02e978d3f Parents: 91a64eb Author: Takuya UESHIN <[email protected]> Authored: Sat May 31 11:30:03 2014 -0700 Committer: Michael Armbrust <[email protected]> Committed: Sat May 31 11:30:16 2014 -0700 ---------------------------------------------------------------------- .../sql/catalyst/analysis/HiveTypeCoercion.scala | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/spark/blob/f9fdf32c/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercion.scala ---------------------------------------------------------------------- diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercion.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercion.scala index 4557d77..326feea 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercion.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/HiveTypeCoercion.scala @@ -264,10 +264,22 @@ trait HiveTypeCoercion { // Skip nodes who's children have not been resolved yet. case e if !e.childrenResolved => e - // Promote SUM to largest types to prevent overflows. + // Promote SUM, SUM DISTINCT and AVERAGE to largest types to prevent overflows. case s @ Sum(e @ DecimalType()) => s // Decimal is already the biggest. case Sum(e @ IntegralType()) if e.dataType != LongType => Sum(Cast(e, LongType)) case Sum(e @ FractionalType()) if e.dataType != DoubleType => Sum(Cast(e, DoubleType)) + + case s @ SumDistinct(e @ DecimalType()) => s // Decimal is already the biggest. + case SumDistinct(e @ IntegralType()) if e.dataType != LongType => + SumDistinct(Cast(e, LongType)) + case SumDistinct(e @ FractionalType()) if e.dataType != DoubleType => + SumDistinct(Cast(e, DoubleType)) + + case s @ Average(e @ DecimalType()) => s // Decimal is already the biggest. + case Average(e @ IntegralType()) if e.dataType != LongType => + Average(Cast(e, LongType)) + case Average(e @ FractionalType()) if e.dataType != DoubleType => + Average(Cast(e, DoubleType)) } } }
