You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Dominic Ricard (JIRA)" <ji...@apache.org> on 2017/05/03 14:41:04 UTC

[jira] [Created] (SPARK-20581) Using AVG or SUM on a INT/BIGINT column with fraction operator will yield BIGINT instead of DOUBLE

Dominic Ricard created SPARK-20581:
--------------------------------------

             Summary: Using AVG or SUM on a INT/BIGINT column with fraction operator will yield BIGINT instead of DOUBLE
                 Key: SPARK-20581
                 URL: https://issues.apache.org/jira/browse/SPARK-20581
             Project: Spark
          Issue Type: Bug
          Components: SQL
    Affects Versions: 1.6.2
            Reporter: Dominic Ricard


We stumbled on this multiple times and every time we are baffled by the behavior of AVG and SUM.

Given the following SQL (Executed through Thrift):
{noformat}
SELECT SUM(col/2) FROM
(SELECT 3 as `col`) t
{noformat}

The result will be "1", when the expected and accurate result is 1.5

Here's the explain plan:
{noformat}
== Physical Plan ==	
TungstenAggregate(key=[], functions=[(sum(cast((cast(col#1519342 as double) / 2.0) as bigint)),mode=Final,isDistinct=false)], output=[_c0#1519344L])	
+- TungstenExchange SinglePartition, None	
   +- TungstenAggregate(key=[], functions=[(sum(cast((cast(col#1519342 as double) / 2.0) as bigint)),mode=Partial,isDistinct=false)], output=[sum#1519347L])	
      +- Project [3 AS col#1519342]	
         +- Scan OneRowRelation[]	
{noformat}

Why the extra cast to BIGINT?



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org