[
https://issues.apache.org/jira/browse/CALCITE-2929?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16796059#comment-16796059
]
Danny Chan commented on CALCITE-2929:
-------------------------------------
[~kgyrtkirk] I definitely agree that
{code:java}
select cast('xxx' as int) IS NULL;
{code}
should not be reduced to
{code:java}
select false ;
{code}
I debug and found that it it in
[code|https://github.com/apache/calcite/blob/600da53545eb9b116aae7692ba287a7acd23d987/core/src/main/java/org/apache/calcite/rex/RexSimplify.java#L750]
that Calcite just decide if the expression cast('xxx' as integer) is null by
cast func's return type, which it not nullable, so it returns false directly.
For cast(or any other func) i think it is strong for nullability, if we make
agreement that any func should throw invalid exception when encounter invalid
value. For cast it is the case.
It is the isNull reduction logic to short-cut the computation-logic, we don't
even have any change to compute the casted value for this case.
I think we should not do any reduction for RexCall is null pattern, because we
never know the right behavior if we do not compute the call, and the invocation
itself make the reduction meaningless.
> Simplification of IS NULL checks are incorrectly assuming that CAST-s are
> possible
> ----------------------------------------------------------------------------------
>
> Key: CALCITE-2929
> URL: https://issues.apache.org/jira/browse/CALCITE-2929
> Project: Calcite
> Issue Type: Bug
> Affects Versions: 1.18.0
> Reporter: Zoltan Haindrich
> Assignee: Zoltan Haindrich
> Priority: Major
> Labels: pull-request-available
> Fix For: 1.19.0
>
> Time Spent: 10m
> Remaining Estimate: 0h
>
> Example:
> {code}
> with ax(s) as (values ('xxx'),(cast(null as character varying)))
> select cast(s as int) IS NULL from ax;
> {code}
> returns a result set; which evaluates
> however 'xxx' is not a valid integer; so an error should be recieved instead
> Another class of almost the same issue:
> {code}
> select cast('xxx' as int) IS NULL;
> {code}
> is also problematic; in that case the not nullability is deduced from the
> fact that the literal's type is not nullable
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)