Issue
I am doing try_cast
as on this column df.select(split(col("spc_value"),lit("~"))[0])
that has value "1.419000"
with
from snowflake.snowpark.types import StructType, StructField, StringType, IntegerType, FloatType, DecimalType, DoubleType, VariantType
from snowflake.snowpark.functions import col,lit,split,try_cast
df.select(try_cast(split(col("spc_value"),lit("~"))[0],DoubleType()))
and column method Column.try_cast
df.select(split(col("spc_value"),lit("~"))[0].try_cast(DoubleType()))
SQL compilation error: Function TRY_CAST cannot be used with arguments of types VARIANT and FLOAT
What have I missed for doing TRY_CAST
here?
Solution
The input of try_cast (whether in Snowflake SQL or Snowpark) MUST be a string. In your example, using split()
creates an object value, so you should explicitly cast that object to a string and then use a try_cast()
to whatever data type you are trying to get it to. Please note that try_cast()
also has a limited set of data types that you can use.
Answered By - Mike Walton
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.