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

CAST(CAST(EMPNO AS VARCHAR) AS INT) should be simplified to EMPNO

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.36.0
    • 1.37.0
    • core

    Description

      Lossless cast removal has been introduced in CALCITE-3712.

      However, VARCHAR's precision is -1, which will not meet the lossless condition in RexUtil

          // 3) From NUMERIC family to CHARACTER family: it depends on the precision/scale
          if (sourceSqlTypeName.getFamily() == SqlTypeFamily.NUMERIC
              && targetSqlTypeName.getFamily() == SqlTypeFamily.CHARACTER) {
            int sourceLength = source.getPrecision() + 1; // include sign
            if (source.getScale() != -1 && source.getScale() != 0) {
              sourceLength += source.getScale() + 1; // include decimal mark
            }
            return target.getPrecision() >= sourceLength; // target.getPrecision() is -1, which will make the optimization fail.
          }
      

      Attachments

        Issue Links

          Activity

            People

              libenchao Benchao Li
              libenchao Benchao Li
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: