[GitHub] [calcite] leonardBang commented on a change in pull request #1491: [CALCITE-3368] Some problems simplifying ‘expression IS NULL’

2019-10-11 Thread GitBox
leonardBang commented on a change in pull request #1491: [CALCITE-3368] Some 
problems simplifying ‘expression IS NULL’ 
URL: https://github.com/apache/calcite/pull/1491#discussion_r333917737
 
 

 ##
 File path: core/src/main/java/org/apache/calcite/rex/RexCall.java
 ##
 @@ -204,7 +204,7 @@ public RelDataType getType() {
 // This reduction allows us to convert it to a semi-join.
 switch (getKind()) {
 case IS_NOT_NULL:
-  return !operands.get(0).getType().isNullable();
+  return RexSimplify.isSafeExpression(this) && 
!operands.get(0).getType().isNullable();
 
 Review comment:
   > we seem to be covered for this already by that the operators result is 
nullable even if all the inputs are non-nullable
   > 
   > ```java
   >   @Test public void testUnsafeSimplify1() {
   > assertFalse(vIntNotNull(0).getType().isNullable());
   > assertTrue(plus(vIntNotNull(0), 
vIntNotNull(1)).getType().isNullable());
   > RexCall c= (RexCall)isNotNull(plus(vIntNotNull(0), vIntNotNull(1)));
   > assertFalse(c.isAlwaysFalse());
   > assertFalse(c.isAlwaysTrue());
   >   }
   > ```
   the ' assertTrue(plus(vIntNotNull(0), 
vIntNotNull(1)).getType().isNullable());' case will fail,
   that I miss something ?
   
   
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [calcite] leonardBang commented on a change in pull request #1491: [CALCITE-3368] Some problems simplifying ‘expression IS NULL’

2019-10-11 Thread GitBox
leonardBang commented on a change in pull request #1491: [CALCITE-3368] Some 
problems simplifying ‘expression IS NULL’ 
URL: https://github.com/apache/calcite/pull/1491#discussion_r333891672
 
 

 ##
 File path: core/src/test/java/org/apache/calcite/test/RexProgramTest.java
 ##
 @@ -1266,21 +1268,53 @@ private void checkExponentialCnf(int n) {
 
 // "null is null" to "true"
 checkSimplify(isNull(nullBool), "true");
-// "(x + y) is null" simplifies to "x is null or y is null"
-checkSimplify(isNull(plus(vInt(0), vInt(1))),
-"OR(IS NULL(?0.int0), IS NULL(?0.int1))");
-checkSimplify(isNull(plus(vInt(0), vIntNotNull(1))), "IS NULL(?0.int0)");
-checkSimplify(isNull(plus(vIntNotNull(0), vIntNotNull(1))), "false");
-checkSimplify(isNull(plus(vIntNotNull(0), vInt(1))), "IS NULL(?0.int1)");
-
-// "(x + y) is not null" simplifies to "x is not null and y is not null"
-checkSimplify(isNotNull(plus(vInt(0), vInt(1))),
-"AND(IS NOT NULL(?0.int0), IS NOT NULL(?0.int1))");
-checkSimplify(isNotNull(plus(vInt(0), vIntNotNull(1))),
-"IS NOT NULL(?0.int0)");
-checkSimplify(isNotNull(plus(vIntNotNull(0), vIntNotNull(1))), "true");
-checkSimplify(isNotNull(plus(vIntNotNull(0), vInt(1))),
-"IS NOT NULL(?0.int1)");
+  }
+
+
+  @Test public void testUnsafeSimplify() {
 
 Review comment:
I agree with you that these tests  should reduce.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [calcite] leonardBang commented on a change in pull request #1491: [CALCITE-3368] Some problems simplifying ‘expression IS NULL’

2019-10-11 Thread GitBox
leonardBang commented on a change in pull request #1491: [CALCITE-3368] Some 
problems simplifying ‘expression IS NULL’ 
URL: https://github.com/apache/calcite/pull/1491#discussion_r333886685
 
 

 ##
 File path: core/src/main/java/org/apache/calcite/rex/RexCall.java
 ##
 @@ -204,7 +204,7 @@ public RelDataType getType() {
 // This reduction allows us to convert it to a semi-join.
 switch (getKind()) {
 case IS_NOT_NULL:
-  return !operands.get(0).getType().isNullable();
+  return RexSimplify.isSafeExpression(this) && 
!operands.get(0).getType().isNullable();
 
 Review comment:
   @kgyrtkirk thanks for review,
If we don't  change here,  tests RexProgramTest#testSimplifyCondition and 
RexProgramTest#testSimplifyCondition2
   will fail after we change the IS_NOT_NULL behavior in RexSimplify.
   Yes, the piece of code is called really frequently and will have higher 
cost, so I wonder we should add a switch for these change.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services