[ 
https://issues.apache.org/jira/browse/CALCITE-7174?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18019338#comment-18019338
 ] 

Konstantin Orlov commented on CALCITE-7174:
-------------------------------------------

> INTEGER-family → DECIMAL(p,s)

I think, the source can be any exact numeric until the following is true:
{code:java}
            int tp = target.getPrecision();
            int ts = target.getScale();
            int sp = source.getPrecision();
            int ss = source.getScale();

            return ts >= ss && (tp - ts) >= (sp - ss);
{code}
I would also considered to add support for Datetime types: the cast is lossless 
iff it's cast within the same type ({{source.getSqlTypeName() == 
target.getSqlTypeName()}}) and target precision >= source precision (e.g cast 
TIME(3) -> TIME(6)).

> Improve detection of lossless casts from INT family to FLOAT/REAL/DECIMAL
> -------------------------------------------------------------------------
>
>                 Key: CALCITE-7174
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7174
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 1.40.0
>            Reporter: Alessandro Solimando
>            Assignee: Alessandro Solimando
>            Priority: Minor
>
> [RexUtil.java#isLossLessCast|https://github.com/apache/calcite/blob/calcite-1.40.0/core/src/main/java/org/apache/calcite/rex/RexUtil.java#L1692]
>  doesn't handle casts from the INT family to non-INT numeric are not covered 
> at all and always considered lossy.
> This ticket proposes to detect the following additional cases as being 
> lossless:
> - INTEGER-family (excluding BIGINT) → DOUBLE
> - SMALLINT/TINYINT → REAL
> - INTEGER-family → DECIMAL(p,s) is lossless iff the integer part capacity (p 
> - s) is large enough (10 for INTEGER, 19 for BIGINT, etc.)
> The newly supported cases must (at least) be covered appropriately in 
> _RexLosslessCastTest_.
> The method has been introduced in Calcite 1.22 and it's still marked as 
> experimental despite being [in 
> use|https://github.com/search?q=repo%3Aapache/calcite%20isLosslessCast&type=code]
>  for years now in several key components, this ticket also proposes promote 
> it to "stable".



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

Reply via email to