支点星火斯卡拉非数字表 [英] Pivot non-numeric table in Spark Scala

查看:263
本文介绍了支点星火斯卡拉非数字表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时可以转动,在星火斯卡拉非数字值的表?我审查,以下两个堆栈的问题。

枢轴星火数据框

在列表中的案例当星火SQL语句

继中的案例当列表的问题,我可以将我的数据,使每个数据类型是列,但对于每个实体数据类型组合一排中的步骤。

  ID标签值
1美国富
1英国酒吧
1 CA巴兹
2 US呼
2 UK哈
2 CA华ID美国英国CA
美孚1
1条
1巴兹
2呼
2哈
3华

有没有第一个非空功能,可以折叠的多行每个实体逼到一个?

  ID美国英国CA
1富酒吧巴兹
2呼哈华


解决方案

您可以考虑在方法(或 aggregateByKey )。你只需要编写适当的funtions在每个位置,以获得非空元素。

Is it possible to pivot a table with non-numeric values in Spark Scala? I have reviewed the following two Stack questions.

Pivot Spark Dataframe

List in the Case-When Statement in Spark SQL

Following the steps in the "List in the Case-When" question, I can transform my data so that each data type is a column, but there is a row for each entity-data type combination.

id    tag    value
1     US     foo
1     UK     bar
1     CA     baz
2     US     hoo
2     UK     hah
2     CA     wah

id    US    UK    CA
1     foo
1           bar
1                 baz
2     hoo
2           hah
3                 wah

Is there a "first non-null" function that can collapse the multiple rows for each entity into just one?

id    US    UK    CA
1     foo   bar   baz
2     hoo   hah   wah

解决方案

You may consider the aggregate method (or aggregateByKey). You just need to write the proper funtions to get the non-null element at each position.

这篇关于支点星火斯卡拉非数字表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆