snowflake.snowpark.functions.explode¶

snowflake.snowpark.functions.explode(col: Union[Column, str]) → TableFunctionCall[source]¶

Flattens a given array or map type column into individual rows. The default column name for the output column in case of array input column is VALUE, and is KEY and VALUE in case of map input column.

Examples::
>>> df = session.create_dataframe([[1, [1, 2, 3], {"Ashi Garami": "Single Leg X"}, "Kimura"],
...                                [2, [11, 22], {"Sankaku": "Triangle"}, "Coffee"]],
...                                schema=["idx", "lists", "maps", "strs"])
>>> df.select(df.idx, explode(df.lists)).sort(col("idx")).show()
-------------------
|"IDX"  |"VALUE"  |
-------------------
|1      |1        |
|1      |2        |
|1      |3        |
|2      |11       |
|2      |22       |
-------------------
Copy
>>> df.select(df.strs, explode(df.maps)).sort(col("strs")).show()
-----------------------------------------
|"STRS"  |"KEY"        |"VALUE"         |
-----------------------------------------
|Coffee  |Sankaku      |"Triangle"      |
|Kimura  |Ashi Garami  |"Single Leg X"  |
-----------------------------------------
Copy
>>> df.select(explode(col("lists")).alias("uno")).sort(col("uno")).show()
---------
|"UNO"  |
---------
|1      |
|2      |
|3      |
|11     |
|22     |
---------
Copy
>>> df.select(explode('maps').as_("primo", "secundo")).sort(col("primo")).show()
--------------------------------
|"PRIMO"      |"SECUNDO"       |
--------------------------------
|Ashi Garami  |"Single Leg X"  |
|Sankaku      |"Triangle"      |
--------------------------------
Copy