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

Simplify casts which are result of constant reduction

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.38.0
    • None

    Description

      RexSimplify transforms nullable cast expressions with a non-nullable literal operand which type is different from the cast type to another cast expression with a literal operand with the same type as the cast.
      If simplify is called again using the result cast expression of the first simplification we get a literal only as a result.
      Example:
      Initial expression

      CAST(_UTF-16LE'2020-10-30':VARCHAR(2147483647) CHARACTER SET "UTF-16LE"):DATE
      

      where the operand is non-nullable varchar and the result of the cast is nullable date.
      After the first simplify call we get

      CAST(2020-10-30:DATE):DATE
      

      where the operand type is non-nullable date and the cast type is nullable date.
      https://github.com/apache/calcite/blob/8ab0b03326730aa2cc6b476b2cbd8f99799bdacb/core/src/main/java/org/apache/calcite/rex/RexSimplify.java#L2269-L2276

      After the second simplify call we get

      2020-10-30:DATE
      

      where the literal type is non-nullable date
      https://github.com/apache/calcite/blob/8ab0b03326730aa2cc6b476b2cbd8f99799bdacb/core/src/main/java/org/apache/calcite/rex/RexSimplify.java#L2195-L2196

      Attachments

        Issue Links

          Activity

            People

              kkasa Krisztian Kasa
              kkasa Krisztian Kasa
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: