Κοινοποίηση μέσω


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

spark.tvf.posexplode_outer(collection)

Parameters

Parameter Type Description
collection pyspark.sql.Column 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

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|
+---+---+
import pyspark.sql.functions as sf
spark.tvf.posexplode_outer(sf.array()).show()
+----+----+
| pos| col|
+----+----+
|NULL|NULL|
+----+----+
import pyspark.sql.functions as sf
spark.tvf.posexplode_outer(sf.create_map(sf.lit("x"), sf.lit(1.0))).show()
+---+---+-----+
|pos|key|value|
+---+---+-----+
|  0|  x|  1.0|
+---+---+-----+
import pyspark.sql.functions as sf
spark.tvf.posexplode_outer(sf.create_map()).show()
+----+----+-----+
| pos| key|value|
+----+----+-----+
|NULL|NULL| NULL|
+----+----+-----+