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

Julian Hyde commented on CALCITE-2921:
--------------------------------------

OK, if you think that CALCITE-2302 fully fixes this issue, we can go with that. 
Note that in cases like {{NULLIF(NULL, y)}} or {{AVG(NULL)}} it may be 
difficult or impossible to deduce the type of the NULL from other arguments. So 
maybe we need a hybrid of 2302 and 2921. Can you work on getting that into 1.21 
[~danny0405]? If you don't have time, let's commit the fix we have (it's ready 
to go on https://github.com/julianhyde/calcite/tree/2921-naked-nulls) and 
improve it later.

The plan improvements noted by [~kgyrtkirk] in this PR were because several 
NULL:null values became NULL:boolean because of better type deduction of 
internally-created RexNodes. But a better solution is to disallow people 
calling RelBuilder.literal(null) or RexBuilder.constantNull(). I did this in 
[b432756|https://github.com/julianhyde/calcite/commit/b432756e2be9ad0557a56254550eb4438dd0efcf],
 and will push this to master shortly.

> Allow NULL as argument to function calls
> ----------------------------------------
>
>                 Key: CALCITE-2921
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2921
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.18.0
>            Reporter: pengzhiwei
>            Assignee: Julian Hyde
>            Priority: Critical
>              Labels: pull-request-available
>             Fix For: 1.21.0
>
>          Time Spent: 1.5h
>  Remaining Estimate: 0h
>
> Currently {{nullif(null,y)}}  throws exception in verification. This is 
> because translates {{nullif(x,y)}} to a case-when expression, just like "case 
> when x = y then null else x". So when "x" is null literal,a exception throws 
> out as follow:
> {code:java}
>  ELSE clause or at least one THEN clause must be non-NULL
> {code}
> I have test in mysql,"nullif(null,y) works well.So I think we should allow 
> this usage of  "nullif".
> There are two ways to fix this issue:
> 1)  Skip the check for "foundNotNull" in SqlCaseOperator#checkOperandTypes:   
>   
> {code:java}
> if (!foundNotNull) {
>   // according to the sql standard we can not have all of the THEN
>   // statements and the ELSE returning null
>   if (throwOnFailure) {
>     throw callBinding.newError(RESOURCE.mustNotNullInElse());
>   }
>   return false;
> }{code}
> However, as the comment says, we cannot have all of the THEN and ELSE 
> returning null.
> 2) Disable the translation from nullif to case-when and keep "nullif" as it 
> is.
> Any suggestion is welcomed,Thanks!



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Reply via email to