我在配置单元中有一个表,它有一个模式:
root
|-- startdate: string (nullable = true)
|-- enddate: string (nullable = true)
|-- items: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- _id: string (nullable = true)
| | |-- name: string (nullable = true)
| | |-- .......: string (nullable = true)
| | |-- otherfields: string (nullable = true)
我只想从items数组字段中获取\u id和name列,即:
|-- items: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- _id: string (nullable = true)
| | |-- name: string (nullable = true)
有没有一种方法可以做到这一点,而不必在spark本身进行额外的转换,这样就只从配置单元中检索实际的列?
我用的是spark 2.2。
1条答案
按热度按时间lo8azlld1#
您可以尝试以下操作:
尽管可能会导致:
在spark 2.4+中,您可以尝试使用U-zip