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

snowflake.snowpark.functions.as_real¶

snowflake.snowpark.functions.as_real(variant: Union[Column, str]) → Column[source]¶

Casts a VARIANT value to a floating-point value.

Example:

>>> from snowflake.snowpark.types import VariantType, StructType, StructField, DoubleType
>>> schema=StructType([StructField("radius", DoubleType()),  StructField("radius_v", VariantType())])
>>> df = session.create_dataframe(data=[[2.0, None]], schema=schema)
>>> df.radius_v = to_variant(df.radius)
>>> df.select(df.radius_v.as_("radius_v"), df.radius).collect()
[Row(RADIUS_V='2.000000000000000e+00', RADIUS=2.0)]
>>> df.select(as_real(df.radius_v).as_("real_radius_v"), df.radius).collect()
[Row(REAL_RADIUS_V=2.0, RADIUS=2.0)]
Copy