snowflake.snowpark.functions.explode¶
- snowflake.snowpark.functions.explode(col: ColumnOrName) 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 isKEYandVALUEin 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)).show() ------------------- |"IDX" |"VALUE" | ------------------- |1 |1 | |1 |2 | |1 |3 | |2 |11 | |2 |22 | -------------------
>>> df.select(df.strs, explode(df.maps)).show() ----------------------------------------- |"STRS" |"KEY" |"VALUE" | ----------------------------------------- |Kimura |Ashi Garami |"Single Leg X" | |Coffee |Sankaku |"Triangle" | -----------------------------------------
>>> df.select(explode(col("lists")).alias("uno")).show() --------- |"UNO" | --------- |1 | |2 | |3 | |11 | |22 | ---------
>>> df.select(explode('maps').as_("primo", "secundo")).show() -------------------------------- |"PRIMO" |"SECUNDO" | -------------------------------- |Ashi Garami |"Single Leg X" | |Sankaku |"Triangle" | --------------------------------