snowflake.snowpark.functions.typeof

snowflake.snowpark.functions.typeof(col: Union[Column, str]) Column[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.16.0/src/snowflake/snowpark/functions.py#L5024-L5047)

Reports the type of a value stored in a VARIANT column. The type is returned as a string.

For columns where all rows share the same type, the result of typeof is the underlying Snowflake column type.

Example:

>>> df = session.create_dataframe([1, 2, 3], schema=["A"])
>>> df.select(typeof(col("A")).as_("ans")).collect()
[Row(ANS='INTEGER'), Row(ANS='INTEGER'), Row(ANS='INTEGER')]
Copy

For columns of VARIANT type, the underlying stored type is returned.

Example:

>>> from snowflake.snowpark.types import VariantType, StructType, StructField
>>> schema = StructType([StructField("A", VariantType())])
>>> df = session.create_dataframe([1, 3.1, 'test'], schema=schema)
>>> df.select(typeof(col("A")).as_("ans")).collect()
[Row(ANS='INTEGER'), Row(ANS='DECIMAL'), Row(ANS='VARCHAR')]
Copy
语言: 中文