spark 中当列的类型为 Array 或者 Map 的时候,如何判断两列是否相等

2017-11-24 11:01:00 +08:00
 linuxchild

Schema 如下:

 |-- list: array (nullable = true)
 |    |-- element: map (containsNull = true)
 |    |    |-- key: string
 |    |    |-- value: array (valueContainsNull = true)
 |    |    |    |-- element: struct (containsNull = true)
 |    |    |    |    |-- Date: integer (nullable = true)
 |    |    |    |    |-- Name: string (nullable = true)
 |-- list2: array (nullable = true)
 |    |-- element: map (containsNull = true)
 |    |    |-- key: string
 |    |    |-- value: array (valueContainsNull = true)
 |    |    |    |-- element: struct (containsNull = true)
 |    |    |    |    |-- Date: integer (nullable = true)
 |    |    |    |    |-- Name: string (nullable = true)

想过滤出来 list 和 list2 相等的数据,该如何判断?

使用filter($"list" === $"list2")判断会提示错误:

org.apache.spark.sql.AnalysisException: cannot resolve '(`list` = `list2`)' due to data type mismatch: Cannot use map type in EqualTo, but the actual input type is array<map<string,array<str
uct<Date:int,Name:string>>>>.;;

以上,感谢~

2395 次点击
所在节点    问与答
4 条回复
linuxchild
2017-11-24 11:40:40 +08:00
木有人搞么
MasterC
2017-11-24 11:43:26 +08:00
自己写 function 进行遍历比较
czheo
2017-11-24 11:45:35 +08:00
udf
linuxchild
2017-11-24 15:55:35 +08:00
@MasterC 嗯,刚刚搞出来了,貌似只能自己写 UDF 了


@czheo 嗯,的确只能这样,感谢

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/409144

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX