[ https://issues.apache.org/jira/browse/CALCITE-3746?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17038244#comment-17038244 ]
Chunwei Lei commented on CALCITE-3746: -------------------------------------- {quote}why don't you add the metadata to your user-defined-functions instead? If you add the metadata, then Calcite would never call the function with null arguments, and it would enable Calcite to optimize the queries better. For example, can you declare the function as a strict one? That would tell Calcite the function always returns null if any of the arguments is null. {quote} You are assuming that every execution engine has such annotation and all udfs should return null or other same value. What should I do if I want a udf which returns 0 while another udf returns -1 when meeting NULL? {quote}Note: RexSimplify code is huge. It deals with lots of things, and I don't see a way of adding an option that would treat `is not null` in every possible case. Then I don't even get what you mean by "retain order" because predicates might float all over the place. There is no order. RexSimplify might infer the predicates, etc, etc {quote} Even though RexSimplify might infer the predicates, it doesn't change the order for other operators, except IS NOT NULL and NOT. For instance, it doesn't change {{a>1 and b<1}} to {{b<1 and a>1}}. What [~pzw2018]'s pr does is to retain order for IS NOT NULL. Why should we always put {{IS NOT NULL}} at the end? > 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: Chunwei Lei > 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)