You are viewing documentation about an older version (1.12.1). View latest version

snowflake.snowpark.functions.object_agg

snowflake.snowpark.functions.object_agg(key: Union[Column, str], value: Union[Column, str]) Column[source]

Returns one OBJECT per group. For each key-value input pair, where key must be a VARCHAR and value must be a VARIANT, the resulting OBJECT contains a key-value field.

Example:

>>> from snowflake.snowpark.types import StructType, StructField, VariantType, StringType
>>> df = session.create_dataframe(
...     [["name", "Joe"], ["zip", "98004"]],
...     schema=StructType([StructField("k", StringType()), StructField("v", VariantType())])
... )
>>> df.select(object_agg(col("k"), col("v")).alias("result")).show()
--------------------
|"RESULT"          |
--------------------
|{                 |
|  "name": "Joe",  |
|  "zip": "98004"  |
|}                 |
--------------------
Copy