【发布时间】:2021-07-12 03:31:56
【问题描述】:
我有以下架构的数据框。我希望包括嵌套字段在内的所有列都应按字母顺序排序。我想要它在 scala spark 中。
root
|-- metadata2: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- attribute2: string (nullable = true)
| | |-- attribute1: string (nullable = true)
|-- metadata3: string (nullable = true)
|-- metadata1: struct (containsNull = true)
| |-- attribute2: string (nullable = true)
| |-- attribute1: string (nullable = true)
当我使用 schema.sortBy(_.name) 进行排序时,我得到了 schema(嵌套数组和结构类型字段未排序)
root
|-- metadata1: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- attribute2: string (nullable = true)
| | |-- attribute1: string (nullable = true)
|-- metadata2: struct (containsNull = true)
| |-- attribute2: string (nullable = true)
| |-- attribute1: string (nullable = true)
|-- metadata3: string (nullable = true)
我想要的架构如下。 (即使是 metadata1(ArrayType) 和 metadata2(StructType) 里面的列也要排序)
root
|-- metadata1: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- attribute1: string (nullable = true)
| | |-- attribute2: string (nullable = true)
|-- metadata2: struct (containsNull = true)
| |-- attribute1: string (nullable = true)
| |-- attribute2: string (nullable = true)
|-- metadata3: string (nullable = true)
提前致谢。
【问题讨论】:
标签: scala apache-spark struct apache-spark-sql