snowflake.snowpark.functions.map_pick

snowflake.snowpark.functions.map_pick(map_col: Union[snowflake.snowpark.column.Column, str], *keys: Union[snowflake.snowpark.column.Column, str]) Column[source]

Returns a new map containing some of the key-value pairs from an existing map.

To identify the key-value pairs to include in the new map, pass in the keys as arguments. If a specified key is not present in the input map, the key is ignored.

Parameters:
  • map_col (ColumnOrName) – The map column to pick from

  • *keys (ColumnOrName) – Additional keys to pick

Returns:

A new map containing the selected key-value pairs

Return type:

Column

Examples::
>>> from snowflake.snowpark.functions import  lit, to_variant, col
>>> df = session.sql("SELECT {'a':1,'b':2,'c':3}::MAP(VARCHAR,NUMBER) as map_col")
>>> df.select(to_variant(map_pick(df["map_col"], lit("a"), lit("b"))).alias("result")).collect()
[Row(RESULT='{\n  "a": 1,\n  "b": 2\n}')]
Copy

# Examlpe sending an array of keys >>> from snowflake.snowpark.functions import map_pick, to_variant, col >>> df = session.sql(“SELECT {‘a’:1,’b’:2,’c’:3}::MAP(VARCHAR,NUMBER) as map_col, ARRAY_CONSTRUCT(‘a’,’b’) as keys_arr”) >>> df.select(to_variant(map_pick(col(“map_col”), col(“keys_arr”))).alias(“RESULT”)).collect() [Row(RESULT=’{n “a”: 1,n “b”: 2n}’)]