通过


TableValuedFunction.inline_outer

将结构数组分解为一个表。 与内联不同,如果数组为 null 或为空,则为每个嵌套列生成 null。

Syntax

spark.tvf.inline_outer(input)

参数

参数 类型 Description
input pyspark.sql.Column 要分解的值的输入列。

退货

pyspark.sql.DataFrame:具有爆炸结构行的数据帧;如果数组为空或 null,则为 null 值。

例子

import pyspark.sql.functions as sf
spark.tvf.inline_outer(sf.array(
    sf.named_struct(sf.lit("a"), sf.lit(1), sf.lit("b"), sf.lit(2)),
    sf.named_struct(sf.lit("a"), sf.lit(3), sf.lit("b"), sf.lit(4))
)).show()
+---+---+
|  a|  b|
+---+---+
|  1|  2|
|  3|  4|
+---+---+
import pyspark.sql.functions as sf
spark.tvf.inline_outer(sf.array().astype("array<struct<a:int,b:int>>")).show()
+----+----+
|   a|   b|
+----+----+
|NULL|NULL|
+----+----+