【发布时间】:2018-10-17 07:38:22
【问题描述】:
我有一个数据框,其中包含一个键列和一个包含结构数组的列。 Schema 如下所示。
root
|-- id: string (nullable = true)
|-- desc: array (nullable = false)
| |-- element: struct (containsNull = true)
| | |-- name: string (nullable = true)
| | |-- age: long (nullable = false)
数组“desc”可以有任意数量的空值。我想使用 spark 1.6 创建一个最终的数据框,其中的数组没有任何空值:
一个例子是:
Key . Value
1010 . [[George,21],null,[MARIE,13],null]
1023 . [null,[Watson,11],[John,35],null,[Kyle,33]]
我希望最终的数据框为:
Key . Value
1010 . [[George,21],[MARIE,13]]
1023 . [[Watson,11],[John,35],[Kyle,33]]
我尝试使用 UDF 和案例类来执行此操作,但得到了
java.lang.ClassCastException: org.apache.spark.sql.catalyst.expressions.GenericRowWithSchema cannot be cast to....
非常感谢任何帮助,如果需要,我更愿意在不转换为 RDD 的情况下这样做。另外我是 spark 和 scala 的新手,所以提前谢谢!!!
【问题讨论】:
标签: scala apache-spark spark-dataframe