pyspark.sql.tvf.TableValuedFunction.explode_outer#

TableValuedFunction.explode_outer(collection)[source]#

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.

New in version 4.0.0.

Parameters
collectionColumn

target column to work on.

Returns
DataFrame

Examples

>>> import pyspark.sql.functions as sf
>>> spark.tvf.explode_outer(sf.array(sf.lit("foo"), sf.lit("bar"))).show()
+---+
|col|
+---+
|foo|
|bar|
+---+
>>> spark.tvf.explode_outer(sf.array()).show()
+----+
| col|
+----+
|NULL|
+----+
>>> spark.tvf.explode_outer(sf.create_map(sf.lit("x"), sf.lit(1.0))).show()
+---+-----+
|key|value|
+---+-----+
|  x|  1.0|
+---+-----+
>>> spark.tvf.explode_outer(sf.create_map()).show()
+----+-----+
| key|value|
+----+-----+
|NULL| NULL|
+----+-----+