pyspark.sql.tvf.TableValuedFunction.posexplode_outer#
- TableValuedFunction.posexplode_outer(collection)[source]#
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.New in version 4.0.0.
- Parameters
- collection
Column
target column to work on.
- collection
- Returns
DataFrame
Examples
>>> import pyspark.sql.functions as sf >>> spark.tvf.posexplode_outer(sf.array(sf.lit("foo"), sf.lit("bar"))).show() +---+---+ |pos|col| +---+---+ | 0|foo| | 1|bar| +---+---+ >>> spark.tvf.posexplode_outer(sf.array()).show() +----+----+ | pos| col| +----+----+ |NULL|NULL| +----+----+ >>> spark.tvf.posexplode_outer(sf.create_map(sf.lit("x"), sf.lit(1.0))).show() +---+---+-----+ |pos|key|value| +---+---+-----+ | 0| x| 1.0| +---+---+-----+ >>> spark.tvf.posexplode_outer(sf.create_map()).show() +----+----+-----+ | pos| key|value| +----+----+-----+ |NULL|NULL| NULL| +----+----+-----+