You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Sergey Nuyanzin (Jira)" <ji...@apache.org> on 2024/05/06 22:20:05 UTC

[jira] [Closed] (CALCITE-6147) CAST(CAST(EMPNO AS VARCHAR) AS INT) should be simplified to EMPNO

     [ https://issues.apache.org/jira/browse/CALCITE-6147?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sergey Nuyanzin closed CALCITE-6147.
------------------------------------

Resolved in release 1.37.0 (2024-05-06)

> 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
>
>
> 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)