Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-4861

Optimization of chained CAST calls can lead to unexpected behavior

    XMLWordPrintableJSON

Details

    Description

      Simplification of Cast chained calls can lead to unexpected behaviour:

      CAST(CAST(CAST(123456 AS TINYINT) AS INT) AS BIGINT)

      is simplified to 

      CAST(123456 AS BIGINT)

      and returns 123456 with BIGINT data type, where the first inner cast as TINYINT should already fail because the value is out of range.

      For example, for PostgreSQL:

      postgres=# select 123456::smallint::int::bigint;
      ERROR: smallint out of range

      Attachments

        Activity

          People

            libenchao Benchao Li
            matriv Marios Trivyzas
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 2.5h
                2.5h