Description
Under ANSI mode(spark.sql.ansi.enabled=true), the function invocation of Spark SQL:
- In general, it follows the `Store assignment` rules as storing the input values as the declared parameter type of the SQL functions
- Special rules apply for string literals and untyped NULL. A NULL can be promoted to any other type, while a string literal can be promoted to any simple data type.
> SET spark.sql.ansi.enabled=true; -- implicitly cast Int to String type > SELECT concat('total number: ', 1); total number: 1 -- implicitly cast Timestamp to Date type > select datediff(now(), current_date); 0 -- specialrule: implicitly cast String literal to Double type > SELECT ceil('0.1'); 1 -- specialrule: implicitly cast NULL to Date type > SELECT year(null); NULL > CREATE TABLE t(s string); -- Can't store String column as Numeric types. > SELECT ceil(s) from t; Error in query: cannot resolve 'CEIL(spark_catalog.default.t.s)' due to data type mismatch -- Can't store String column as Date type. > select year(s) from t; Error in query: cannot resolve 'year(spark_catalog.default.t.s)' due to data type mismatch