Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-42473

An explicit cast will be needed when INSERT OVERWRITE SELECT UNION ALL

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.3.1
    • 3.3.3
    • Optimizer
    • None
    • spark 3.3.1

    Description

      when 'union all' and one select statement use Literal as column value , the other select statement  has computed expression at the same column , then the whole statement will compile failed. A explicit cast will be needed.

      for example:

      explain

      INSERT OVERWRITE TABLE test.spark33_decimal_orc

      select null as amt1, cast('256.99' as decimal(20,8)) as amt2

      union all

      select cast('200.99' as decimal(20,8))/100 as amt1,cast('256.99' as decimal(20,8)) as amt2;

      will got error : 

      org.apache.spark.sql.catalyst.expressions.Literal cannot be cast to org.apache.spark.sql.catalyst.expressions.AnsiCast

      The SQL will need to change to : 

      explain

      INSERT OVERWRITE TABLE test.spark33_decimal_orc

      select null as amt1,cast('256.99' as decimal(20,8)) as amt2

      union all

      select cast(cast('200.99' as decimal(20,8))/100 as decimal(20,8)) as amt1,cast('256.99' as decimal(20,8)) as amt2;

       

      but this is not need in spark3.2.1 , is this a bug for spark3.3.1 ? 

      Attachments

        Activity

          People

            runyao Runyao.Chen
            kevinshin kevinshin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: