首页 > 解决方案 > Pyspark 将 StrucType[ArrayType, StructureType] 转换为 ArrayType[ArrayType,ArrayType]

问题描述

我有一个列 'COL_NAME' 的 DF,其中包含一个 StructType 格式:

StructType[StructType, StructType, ArrayType, ArrayType, StructType, ArrayType, ArrayType]

上面的 StructType 从 UDF 返回。我需要将它转换为所有 ArrayType

ArrayType[ArrayType, ArrayType, ArrayType, ArrayType, ArrayType, ArrayType, ArrayType]

怎么做。太感谢了

更新

例子:

array need to return :
[[before], [after], [from_tbl], [where_tbl], [to_tbl], [lst_tbl], [dbinfo]]

where before/after is a list
before, after = [[query_type,out,[from],[where]],[query_type,out,[from],[where]]]

where querytype is string, out is string, but from, where is list, not same level

to_tbl = [write_mode, [table_name], table_action]
from_tbl, where_tbl, from, where, table_name, lst_tbl, db_info = [a,b,c]

当我定义 UDF 时,我必须定义返回模式,嵌套数组不是同一级别,所以我无法为所有人定义有效模式

标签: dataframepysparkuser-defined-functions

解决方案


推荐阅读