【发布时间】:2017-12-03 13:08:52
【问题描述】:
我有一个 DataFrame,它有多个列,其中一些是结构。像这样的
root
|-- foo: struct (nullable = true)
| |-- bar: string (nullable = true)
| |-- baz: string (nullable = true)
|-- abc: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- def: struct (nullable = true)
| | | |-- a: string (nullable = true)
| | | |-- b: integer (nullable = true)
| | | |-- c: string (nullable = true)
我想在baz 列上应用UserDefinedFunction 以将baz 替换为baz 的函数,但我不知道该怎么做。这是所需输出的示例(请注意,baz 现在是 int)
root
|-- foo: struct (nullable = true)
| |-- bar: string (nullable = true)
| |-- baz: int (nullable = true)
|-- abc: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- def: struct (nullable = true)
| | | |-- a: string (nullable = true)
| | | |-- b: integer (nullable = true)
| | | |-- c: string (nullable = true)
看起来DataFrame.withColumn 仅适用于顶级列,但不适用于嵌套列。我正在使用 Scala 来解决这个问题。
有人可以帮我解决这个问题吗?
谢谢
【问题讨论】:
标签: scala apache-spark dataframe udf