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

snowflake.snowpark.functions.to_array

snowflake.snowpark.functions.to_array(e: Union[Column, str]) Column[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.16.0/src/snowflake/snowpark/functions.py#L6267-L6283)

Converts any value to an ARRAY value or NULL (if input is NULL).

Example:

>>> df = session.create_dataframe([1, 2, 3, 4], schema=['a'])
>>> df.select(to_array(col('a')).as_('ans')).collect()
[Row(ANS='[\n  1\n]'), Row(ANS='[\n  2\n]'), Row(ANS='[\n  3\n]'), Row(ANS='[\n  4\n]')]


>>> from snowflake.snowpark import Row
>>> df = session.create_dataframe([Row(a=[1, 2, 3]), Row(a=None)])
>>> df.select(to_array(col('a')).as_('ans')).collect()
[Row(ANS='[\n  1,\n  2,\n  3\n]'), Row(ANS=None)]
Copy
Language: English