Benchao Li created CALCITE-6147:
-----------------------------------

             Summary: CAST(CAST(EMPNO AS VARCHAR) AS INT) should be simplified 
to EMPNO
                 Key: CALCITE-6147
                 URL: https://issues.apache.org/jira/browse/CALCITE-6147
             Project: Calcite
          Issue Type: Improvement
          Components: core
    Affects Versions: 1.36.0
            Reporter: Benchao Li
            Assignee: Benchao Li


Lossless case removal has been introduced in CALCITE-3712.

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

{code:java}
    // 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.
    }
{code}




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to