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