Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-34246 New type coercion syntax rules in ANSI mode
  3. SPARK-37438

ANSI mode: Use store assignment rules for resolving function invocation

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.3.0
    • 3.3.0
    • SQL
    • None

    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
      

      Attachments

        Activity

          People

            Gengliang.Wang Gengliang Wang
            Gengliang.Wang Gengliang Wang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: