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

Stamatis Zampetakis commented on CALCITE-7145:
----------------------------------------------

[~thomas.rebele] I like the idea of improving safety by checking for "special" 
arguments/literals although I am not sure if the added complexity/risk is worth 
the effort. I will review the new PR and will post further comments there.

Currently, IS NULL(+(null, CAST($0):INTEGER)) is simplified to true but this is 
a wrong simplification for the standard unsafe cast and shouldn't happen in the 
first place. Since Druid at the moment uses the standard CAST I would say that 
the new plan is the expected one. In fact, I would go even further and say that 
pushing a regular CAST to Druid is incorrect since the semantics are different. 
Anyways, I feel that this is a separate issue thus I logged CALCITE-7271 
although I wouldn't rush fixing it since it seems a rather minor edge case.

[~julianhyde] Having a new sequence operator for simplifying unsafe operations 
is a nice idea. I will keep it in mind for the future if we find that it's 
really beneficial/important to perform such simplifications.

After checking a bit more the code around the simplification of IS [NOT] NULL I 
found that the problem reported here is roughly the same to CALCITE-2929 and 
CALCITE-3457 but for different operators. The solution that was adopted back 
then was to consider that the operators (CAST, ITEM) have [special nullability 
semantics|https://github.com/apache/calcite/blob/8b5c17e51e0c9c3f8e3db17c8d449e67e4e2974a/core/src/main/java/org/apache/calcite/rex/RexSimplify.java#L1279].
 For this reason, the simplification bails out when it encounters CAST and 
ITEM. I am highlighting this now since we may want to revisit this part of the 
code in a follow-up for making the handling more uniform.

> RexSimplify should not simplify IS NULL(10/0)
> ---------------------------------------------
>
>                 Key: CALCITE-7145
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7145
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Thomas Rebele
>            Assignee: Thomas Rebele
>            Priority: Major
>              Labels: pull-request-available
>
> RexSimplify incorrectly simplifies {{IS NULL(10/0)}} to false and {{IS NOT 
> NULL(10,0)}} to true
> In other DBMS it's either the inverse (sqlite, MySQL, MariaDB), or they throw 
> an exception in both cases (Oracle, Postgres). The behavior was also 
> mentioned in a comment on CALCITE-3368.
> Is it right that throwing an exception during query execution is the expected 
> behavior according to the SQL standard?



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

Reply via email to