[
https://issues.apache.org/jira/browse/CALCITE-2921?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16792892#comment-16792892
]
Julian Hyde commented on CALCITE-2921:
--------------------------------------
There are a lot of places that Calcite does not allow NULL literals. This is to
comply with the SQL standard, because in such cases we cannot deduce the type
of the NULL.
We have discussed adding a "lenient mode" where we would allow such naked nulls.
I don't know whether this case counts as a "naked null" per the SQL standard.
If it does, Calcite should throw a user error during validation. If it does
not, Calcite should give the correct result. (I'm saying 'should' not 'does'.)
Can you figure that out?
What happens when you try {{NULLIF(CAST(NULL AS INTEGER), y)}}? That should be
valid. I hope we succeed.
> nullif(null,y) throws exception in verification
> ------------------------------------------------
>
> 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: pengzhiwei
> Priority: Critical
>
> Currently calcite will translate "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.3#76005)