TableValuedFunction.explode_outer
Returns a DataFrame containing a new row for each element with position in the given array or map. Unlike explode, if the array/map is null or empty then null is produced. Uses the default column name col for elements in the array and key and value for elements in the map unless specified otherwise.
Syntax
Python
spark.tvf.explode_outer(collection)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| Target column to work on. |
Returns
pyspark.sql.DataFrame: A DataFrame with a new row for each element, or null if the collection is empty or null.
Examples
Python
import pyspark.sql.functions as sf
spark.tvf.explode_outer(sf.array(sf.lit("foo"), sf.lit("bar"))).show()
Output
+---+
|col|
+---+
|foo|
|bar|
+---+
Python
import pyspark.sql.functions as sf
spark.tvf.explode_outer(sf.array()).show()
Output
+----+
| col|
+----+
|NULL|
+----+
Python
import pyspark.sql.functions as sf
spark.tvf.explode_outer(sf.create_map(sf.lit("x"), sf.lit(1.0))).show()
Output
+---+-----+
|key|value|
+---+-----+
| x| 1.0|
+---+-----+
Python
import pyspark.sql.functions as sf
spark.tvf.explode_outer(sf.create_map()).show()
Output
+----+-----+
| key|value|
+----+-----+
|NULL| NULL|
+----+-----+