[ https://issues.apache.org/jira/browse/CALCITE-6147?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Benchao Li updated CALCITE-6147: -------------------------------- Fix Version/s: 1.37 > 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 > Priority: Major > Labels: pull-request-available > Fix For: 1.37.0, 1.37 > > > Lossless cast removal has been introduced in CALCITE-3712. > However, {{{}VARCHAR{}}}'s precision is {{{}-1{}}}, which will not meet the > lossless condition in > [RexUtil|https://github.com/apache/calcite/blob/bd7d4e89c5c4a01d4e5897fc04be224dcddaecae/core/src/main/java/org/apache/calcite/rex/RexUtil.java#L1694-L1701] > {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)