【发布时间】:2021-10-23 21:05:40
【问题描述】:
我有一个架构
-- item: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- key: string (nullable = true)
| | |-- type: string (nullable = true)
| | |-- one: string (nullable = true)
| | |-- two: boolean (nullable = true)
| | |-- three: long (nullable = true)
- 我想为数组中的每个键创建一个新列,它的值应该基于类型(如果 item.type = "one",那么该键的值将是 element.one)
- 如果它的键等于“电子”,我想从数组中删除 struct(item)
【问题讨论】:
-
要将结构数组分解为列,您可以使用inline,即
df.selectExpr("inline(item)")
标签: scala apache-spark apache-spark-sql user-defined-functions scala-collections