【发布时间】:2018-05-08 08:50:20
【问题描述】:
我有一个包含两列(键、值)的 DataFrame,如下所示:
+------------+--------------------+
| key| value|
+------------+--------------------+
|[sid2, sid5]| value1 |
| [sid2]| value2 |
| [sid6]| value3 |
+------------+--------------------+
键是一组字符串,我想应用 reduceByKey 转换,如果两个键之间存在交集,则它们相等,输出应如下所示:
+------------+--------------------+
| key| value|
+------------+--------------------+
|[sid2, sid5]| [value1, value2] |
| [sid6]| value3 |
+------------+--------------------+
我尝试使用 case 类作为 key wapper 并覆盖 equals 和 hashCode 函数,但它不起作用 (SPARK-2620)。
知道怎么做吗? 提前致谢。
更新 - DataFrame 架构:
root
|-- id1: array (nullable = true)
| |-- element: string (containsNull = true)
|-- events1: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- sid: string (nullable = true)
| | |-- uid: string (nullable = true)
| | |-- action: string (nullable = true)
| | |-- touchPoint: string (nullable = true)
| | |-- result: string (nullable = true)
| | |-- timestamp: long (nullable = false)
| | |-- url: string (nullable = true)
| | |-- onlineId: long (nullable = false)
| | |-- channel: string (nullable = true)
| | |-- category: string (nullable = true)
| | |-- clientId: long (nullable = false)
| | |-- newUser: boolean (nullable = false)
| | |-- userAgent: string (nullable = true)
| | |-- group: string (nullable = true)
| | |-- pageType: string (nullable = true)
| | |-- clientIP: string (nullable = true)
【问题讨论】:
标签: scala apache-spark dataframe reduce