snowflake.snowpark.functions.explode¶
- snowflake.snowpark.functions.explode(col: Union[Column, str]) TableFunctionCall [source] (https://github.com/snowflakedb/snowpark-python/blob/v1.16.0/src/snowflake/snowpark/functions.py#L1214-L1268)¶
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 isKEY
andVALUE
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 | -------------------
>>> df.select(df.strs, explode(df.maps)).sort(col("strs")).show() ----------------------------------------- |"STRS" |"KEY" |"VALUE" | ----------------------------------------- |Coffee |Sankaku |"Triangle" | |Kimura |Ashi Garami |"Single Leg X" | -----------------------------------------
>>> df.select(explode(col("lists")).alias("uno")).sort(col("uno")).show() --------- |"UNO" | --------- |1 | |2 | |3 | |11 | |22 | ---------
>>> df.select(explode('maps').as_("primo", "secundo")).sort(col("primo")).show() -------------------------------- |"PRIMO" |"SECUNDO" | -------------------------------- |Ashi Garami |"Single Leg X" | |Sankaku |"Triangle" | --------------------------------