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

Alessandro Solimando edited comment on CALCITE-7174 at 9/29/25 9:07 AM:
------------------------------------------------------------------------

Fixed via 
[{{8388201}}|https://github.com/apache/calcite/commit/83882017b188222a06916145b0f4867b6a7e2b1f],
 thanks [~korlov], [~zhenchen], [~mbudiu] and [~caicancai] for your reviews, 
comments and discussions!


was (Author: asolimando):
Fixed via 
[{{8388201}}|https://github.com/apache/calcite/commit/83882017b188222a06916145b0f4867b6a7e2b1f],
 thanks [~zhenchen], [~mbudiu] and [~caicancai] for your reviews and 
discussions! 

> Improve lossless cast detection for numeric types
> -------------------------------------------------
>
>                 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: Major
>              Labels: pull-request-available
>             Fix For: 1.41.0
>
>
> [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 (signed and unsigned) => INTEGER-family when the target 
> range fully covers the source range, checked via numeric limits
> - DECIMAL(p, s=0) => INTEGER-family when the decimal range is entirely 
> contained in the target integer range
> - INTEGER-family (signed/unsigned) => DECIMAL(p, s) when the integer digits 
> fit within (p - s)
> - DECIMAL(p, s=0) / INTEGER-family => APPROXIMATE numerics when the target 
> has at least as many significant digits
> All other cases, including DECIMAL with non-zero scale, remain conservative 
> and are treated as lossy, to honor the method contract (OK to be incomplete 
> but no false positives).
> 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