[
https://issues.apache.org/jira/browse/CALCITE-5990?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17765392#comment-17765392
]
Runkang He edited comment on CALCITE-5990 at 9/14/23 11:50 PM:
---------------------------------------------------------------
The direct cause is that this issue is introduced by CALCITE-5843, when in
Enumerable's codegen layer, we remove the check for integer overflow[1], and
use forced type conversion like `(byte)130` instead. This seems to be a
regression and need to fix.
Another side, I think we also should check and find overflow problems earlier
in `makeCast` at sql2rel phase, rather than at runtime.
[1][https://github.com/apache/calcite/blame/3aee0b86aa23476cbdecc75ad5d43b936a6fff7b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Expressions.java#L575C7-L575C7]
was (Author: JIRAUSER280488):
The direct cause is that this issue is introduced by CALCITE-5843, when in
Enumerable's codegen layer, we remove the check for integer overflow[1], and
use forced type conversion like `(byte)130` instead. This seems to be a
regression and need to fix.
Another side, I think we also should check and find overflow problems earlier
in `makeCast` at sql2rel phase, rather than at runtime.
[1]
[https://github.com/apache/calcite/blame/3aee0b86aa23476cbdecc75ad5d43b936a6fff7b/linq4j/src/main/java/org/apache/calcite/linq4j/tree/Expressions.java#L575C7-L575C7]
> Explicit cast to numeric type doesn't check overflow
> ----------------------------------------------------
>
> Key: CALCITE-5990
> URL: https://issues.apache.org/jira/browse/CALCITE-5990
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.35.0
> Reporter: Runkang He
> Assignee: Runkang He
> Priority: Major
>
> Explicit cast to numeric type doesn't check overflow, and this issue can be
> reproduced by sqlline:
> {code:sql}
> select cast(empno as tinyint), cast(130 as tinyint) from emps where
> name='Alice'; -- empno is 130
> {code}
> The empno is INT type. The result is:
> {code:sql}
> -126, -126{code}
> I think it should throw exception when overflow.
> At last, this issue was found when to turn on runtime check for
> CalciteSqlOperatorTest in CALCITE-5921.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)