[ 
https://issues.apache.org/jira/browse/SPARK-7549?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14538965#comment-14538965
 ] 

Nicholas Chammas commented on SPARK-7549:
-----------------------------------------

To provide a motivating example for the record (copied from my comment on 
SPARK-7548), consider a DataFrame that looks like this:

{code}
>>> a = {
    'test_name': 'abracadabra',
    'results': [{'time': 14.7}, {'time': 22.3}]
}
>>> df = sqlContext.jsonRDD(sc.parallelize([json.dumps(a)]))
>>> df.printSchema()
root
 |-- results: array (nullable = true)
 |    |-- element: struct (containsNull = true)
 |    |    |-- time: double (nullable = true)
 |-- test_name: string (nullable = true)

>>> print df.select('results.time').collect()
[Row(time=[14.7, 22.3])]
{code}

It is currently not possible to aggregate over the nested {{time}} field as 
follows:

{code}
df.groupBy('test_name').avg('results.time')
{code}

An alternative to supporting this kind of aggregation would be to offer some 
way to "promote" the nested column to a top-level column, like 
[{{explode()}}|SPARK-7548], but the more straightforward solution is to enable 
aggregations on nested columns directly.

> Support aggregating over nested fields
> --------------------------------------
>
>                 Key: SPARK-7549
>                 URL: https://issues.apache.org/jira/browse/SPARK-7549
>             Project: Spark
>          Issue Type: Sub-task
>          Components: SQL
>            Reporter: Reynold Xin
>
> Would be nice to be able to run sum, avg, min, max (and other numeric 
> aggregate expressions) on arrays.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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

Reply via email to