TableValuedFunction.inline
Explodes an array of structs into a table.
This function takes an input column containing an array of structs and returns a new column where each struct in the array is exploded into a separate row.
Syntax
Python
spark.tvf.inline(input)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| Input column of values to explode. |
Returns
pyspark.sql.DataFrame: A DataFrame with exploded struct rows.
Examples
Example 1: Using inline with a single struct array
Python
import pyspark.sql.functions as sf
spark.tvf.inline(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()
Output
+---+---+
| a| b|
+---+---+
| 1| 2|
| 3| 4|
+---+---+
Example 2: Using inline with an empty struct array column
Python
import pyspark.sql.functions as sf
spark.tvf.inline(sf.array().astype("array<struct<a:int,b:int>>")).show()
Output
+---+---+
| a| b|
+---+---+
+---+---+
Example 3: Using inline with a struct array column containing null values
Python
import pyspark.sql.functions as sf
spark.tvf.inline(sf.array(
sf.named_struct(sf.lit("a"), sf.lit(1), sf.lit("b"), sf.lit(2)),
sf.lit(None),
sf.named_struct(sf.lit("a"), sf.lit(3), sf.lit("b"), sf.lit(4))
)).show()
Output
+----+----+
| a| b|
+----+----+
| 1| 2|
|NULL|NULL|
| 3| 4|
+----+----+