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

Chunwei Lei commented on CALCITE-3746:
--------------------------------------

Sorry for the late reply, [~vladimirsitnikov]. You can find a test case in this 
branch: 
[https://github.com/chunweilei/calcite/commit/9905f843b76f3413771f1dd12d3091a2de8d322a].

 
{code:java}
  @Test public void testExpressionOrder() {
    final CalciteAssert.AssertThat with = withUdf();
    final String sql2 = "select\n"
        + "  \"adhoc\".my_str(upper(\"adhoc\".null4(\"name\"))) as p\n"
        + " from \"adhoc\".EMPLOYEES where \"adhoc\".null4(\"name\") is not 
null "
        + " and \"adhoc\".my_str(\"adhoc\".null4(\"name\"))='SEBASTIAN'";
    with.query(sql2)
        .returnsUnordered(
            "P=<SEBASTIAN>");
  }

{code}
In this test case, function {{my_str}} will throw an exception if the parameter 
is NULL. So I write another predicate to make sure the parameter is never NULL. 
Unfortunately, it still throw an exception because 
{{"adhoc".my_str("adhoc".null4("name"))='SEBASTIAN'"}} is executed before 
{{"adhoc".null4("name") is not null}}. 

 

 

> RexSimplify changes the order of IS NOT NULL in And RexNode
> -----------------------------------------------------------
>
>                 Key: CALCITE-3746
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3746
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.20.0
>            Reporter: pengzhiwei
>            Assignee: pengzhiwei
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> The RexSimplify changes the order of IS NOT NULL in And RexNode.The following 
> expression 
> {code:java}
> a is not null and length(a) > 0{code}
> is optimazted to 
> {code:java}
> length(a) > 0 and a is not null{code}
> which will affect the logic short circuit for null-test.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to