snowflake.snowpark.functions.create_map

snowflake.snowpark.functions.create_map(*cols: Union[Column, str, Iterable[Union[Column, str]]]) Column[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.16.0/src/snowflake/snowpark/functions.py#L767-L818)

Transforms multiple column pairs into a single map Column where each pair of columns is treated as a key-value pair in the resulting map.

Parameters:

*cols – A variable number of column names or Column objects that can also be expressed as a list of columns. The function expects an even number of arguments, where each pair of arguments represents a key-value pair for the map.

Returns:

A Column where each row contains a map created from the provided column pairs.

Example

>>> from snowflake.snowpark.functions import create_map
>>> df = session.create_dataframe([("Paris", "France"), ("Tokyo", "Japan")], ("city", "country"))
>>> df.select(create_map("city", "country").alias("map")).show()
-----------------------
|"MAP"                |
-----------------------
|{                    |
|  "Paris": "France"  |
|}                    |
|{                    |
|  "Tokyo": "Japan"   |
|}                    |
-----------------------
Copy
>>> df.select(create_map([df.city, df.country]).alias("map")).show()
-----------------------
|"MAP"                |
-----------------------
|{                    |
|  "Paris": "France"  |
|}                    |
|{                    |
|  "Tokyo": "Japan"   |
|}                    |
-----------------------
Copy
语言: 中文