我有一个镶木地板文件中的数据,该文件有 2 个字段:object_id: String
和alpha: Map<>
.
它被读入 sparkSQL 中的数据框,架构如下所示:
scala> alphaDF.printSchema()
root
|-- object_id: string (nullable = true)
|-- ALPHA: map (nullable = true)
| |-- key: string
| |-- value: struct (valueContainsNull = true)
我正在使用 Spark 2.0,我正在尝试创建一个新的数据框,其中的列需要是地图的object_id
加键,如ALPHA
object_id, key1, key2, key2, ...
我首先想看看我是否至少可以像这样访问地图:
scala> alphaDF.map(a => a(0)).collect()
<console>:32: error: Unable to find encoder for type stored in a Dataset.
Primitive types (Int, String, etc) and Product types (case classes) are
supported by importing spark.implicits._ Support for serializing other
types will be added in future releases.
alphaDF.map(a => a(0)).collect()
但不幸的是,我似乎无法弄清楚如何访问地图的键。
有人可以告诉我一种将object_id
加号映射键作为列名并将映射值作为新数据框中的相应值的方法吗?