Piezīmes
Lai piekļūtu šai lapai, ir nepieciešama autorizācija. Varat mēģināt pierakstīties vai mainīt direktorijus.
Lai piekļūtu šai lapai, ir nepieciešama autorizācija. Varat mēģināt mainīt direktorijus.
Separates a variant object/array into multiple rows containing its fields/elements. Its result schema is struct<pos int, key string, value variant>. pos is the position of the field/element in its parent object/array, and value is the field/element value. key is the field name when exploding a variant object, or is NULL when exploding a variant array. Unlike variant_explode, if the given variant is not a variant array/object, including SQL NULL, variant null, and any other variant values, then NULL is produced.
Syntax
spark.tvf.variant_explode_outer(input)
Parameters
| Parameter | Type | Description |
|---|---|---|
input |
pyspark.sql.Column |
Input column of values to explode. |
Examples
Example 1: Using variant_explode_outer with a variant array
from pyspark.sql import functions as sf
spark.tvf.variant_explode_outer(sf.parse_json(sf.lit('["hello", "world"]'))).show()
+---+----+-------+
|pos| key| value|
+---+----+-------+
| 0|NULL|"hello"|
| 1|NULL|"world"|
+---+----+-------+
Example 2: Using variant_explode_outer with an empty variant array
from pyspark.sql import functions as sf
spark.tvf.variant_explode_outer(sf.parse_json(sf.lit('[]'))).show()
+----+----+-----+
| pos| key|value|
+----+----+-----+
|NULL|NULL| NULL|
+----+----+-----+
Example 3: Using variant_explode_outer with a variant object
from pyspark.sql import functions as sf
spark.tvf.variant_explode_outer(sf.parse_json(sf.lit('{"a": true, "b": 3.14}'))).show()
+---+---+-----+
|pos|key|value|
+---+---+-----+
| 0| a| true|
| 1| b| 3.14|
+---+---+-----+
Example 4: Using variant_explode_outer with an empty variant object
from pyspark.sql import functions as sf
spark.tvf.variant_explode_outer(sf.parse_json(sf.lit('{}'))).show()
+----+----+-----+
| pos| key|value|
+----+----+-----+
|NULL|NULL| NULL|
+----+----+-----+