我有以下模式的数据帧
root
|-- array_column: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- id: long (nullable = true)
| | |-- name: string (nullable = true)
|-- label_info: array (nullable = true)
| |-- element: string (containsNull = true)
|-- extras: string (nullable = true)如何以编程方式发现我的模式包含字符串数组的列或结构数组的列。上面只是一个示例模式。我将拥有动态模式。
到现在为止,我可以做这样的事情
if isinstance(df.schema["array_column"].dataType, ArrayType):但这只能说明该列是arraytype。
发布于 2021-08-02 17:16:14
当您的列是数组列时,可以使用elementType访问它的元素的架构。然后,您可以像这样检查这些元素的类型:
if isinstance(df.schema["array_column"].dataType.elementType, StringType):https://stackoverflow.com/questions/68625553
复制相似问题