【发布时间】:2019-09-11 23:09:41
【问题描述】:
我有一个如下所示的架构。我想知道在火花中选择元素座椅和驱动器然后将其铸成绳子的最佳方法是什么。我正在使用 spark 1.6 的数据框中阅读此内容。
|-- cars: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- carId: string (nullable = true)
| | |-- carCode: string (nullable = true)
| | |-- carNumber: string (nullable = true)
| | |-- features: array (nullable = true)
| | | |-- element: struct (containsNull = true)
| | | | |-- seat: string (nullable = true)
| | | | |-- drive: string (nullable = true)
cars.features 的输出为 json 中的 car_features:
"cars_features":[[{"seat":"Auto","drive":"Manual"}]]
我正在尝试选择“自动”并将其放入数据框列和“手动”并放入另一列。
当前尝试将整个结构返回为:
+-------------------+
|car_features |
+-------------------+
| [[Auto,Manual]] |
+-------------------+
col("car.features").getItem(0).as("car_features_seat")
【问题讨论】:
-
所以您想选择
seat和drive作为数组的数组还是仅作为数组或作为行? -
我编辑了问题以使其更清楚。
-
getItem("key") 不是 0。
标签: apache-spark hadoop apache-spark-sql