2017-09-01 75 views
-1

我有一个数据帧火花斯卡拉 - 合并多发性行成一个

|--id:string (nullable = true) 
|--ddd:struct (nullable = true) 
    |-- aaa: string (nullable = true) 
    |-- bbb: long(nullable = true) 
    |-- ccc: string (nullable = true) 
    |-- eee: long(nullable = true) 

我有这样的

id  | ddd 
-------------------------- 
    1 | [hi,1,this,2] 
    2 | [hello,6,good,3] 
    1 | [hru,2,where,7] 
    3 | [in,4,you,1] 
    2 | [how,4,to,3] 

我想预期的O/P输出:

id | ddd 
    -------------------- 
    1 | [hi,1,this,2],[hru,2,where,7] 
    2 | [hello,6,good,3],[how,4,to,3] 
    3 | [in,4,you,1] 

请帮忙

+0

是,即使可能吗?因为您只是更改列* dddd *的结构,所以它成为一个结构数组,并且聚合 – tricky

+0

正常。可以给我的代码请 – gayathri

回答

4

你可以collect_list如下

import org.apache.spark.sql.functions._ 
df.groupBy("id").agg(collect_list("ddd").as("ddd")) 

collect_set作品,以及

df.groupBy("id").agg(collect_set("ddd").as("ddd")) 
+0

collect_list不工作​​。 – gayathri

+0

最新错误。它的工作虽然 –

+0

它说未定义的函数collect_list – gayathri