You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2020/04/10 22:10:48 UTC

[GitHub] [calcite] vineetgarg02 opened a new pull request #1909: [CALCITE-3914] Improve SubsitutionVisitor to consider RexCall of type PLUS and TIMES for canonicalization (Vineet Garg)

vineetgarg02 opened a new pull request #1909: [CALCITE-3914] Improve SubsitutionVisitor to consider RexCall of type PLUS and TIMES for canonicalization (Vineet Garg)
URL: https://github.com/apache/calcite/pull/1909
 
 
   … 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] jcamachor commented on a change in pull request #1909: [CALCITE-3914] Improve SubsitutionVisitor to consider RexCall of type PLUS and TIMES for canonicalization (Vineet Garg)

Posted by GitBox <gi...@apache.org>.
jcamachor commented on a change in pull request #1909: [CALCITE-3914] Improve SubsitutionVisitor to consider RexCall of type PLUS and TIMES for canonicalization (Vineet Garg)
URL: https://github.com/apache/calcite/pull/1909#discussion_r406995687
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
 ##########
 @@ -345,13 +345,29 @@ private static RexNode canonizeNode(RexBuilder rexBuilder, RexNode condition) {
     case LESS_THAN_OR_EQUAL:
     case GREATER_THAN_OR_EQUAL: {
       RexCall call = (RexCall) condition;
-      final RexNode left = call.getOperands().get(0);
-      final RexNode right = call.getOperands().get(1);
+      RexNode left = call.getOperands().get(0);
+      left = canonizeNode(rexBuilder, left);
+      RexNode right = call.getOperands().get(1);
+      right = canonizeNode(rexBuilder, right);
+      call = (RexCall) rexBuilder.makeCall(call.getOperator(), left, right);
       if (left.toString().compareTo(right.toString()) <= 0) {
         return call;
 
 Review comment:
   You can only return the original call if `left==call.getOperands().get(0) && right==call.getOperands().get(1)`. Below (for + and *), you could check if that is the case too, and return the original call otherwise; it is worth skipping new expression creation in these cases).

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] jcamachor commented on a change in pull request #1909: [CALCITE-3914] Improve SubsitutionVisitor to consider RexCall of type PLUS and TIMES for canonicalization (Vineet Garg)

Posted by GitBox <gi...@apache.org>.
jcamachor commented on a change in pull request #1909: [CALCITE-3914] Improve SubsitutionVisitor to consider RexCall of type PLUS and TIMES for canonicalization (Vineet Garg)
URL: https://github.com/apache/calcite/pull/1909#discussion_r406977531
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
 ##########
 @@ -324,6 +324,8 @@ public static RexNode splitFilter(final RexSimplify simplify,
    */
   private static RexNode canonizeNode(RexBuilder rexBuilder, RexNode condition) {
     switch (condition.getKind()) {
+    case PLUS:
 
 Review comment:
   The code in this block removes duplicate operands (via the `TreeMap`). You will need slightly different code for `PLUS` or `TIMES` (just the sort piece).
   
   Once this is fixed, could you add a test with duplicate operand, e.g,., `x + x` ?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] jcamachor commented on a change in pull request #1909: [CALCITE-3914] Improve SubsitutionVisitor to consider RexCall of type PLUS and TIMES for canonicalization (Vineet Garg)

Posted by GitBox <gi...@apache.org>.
jcamachor commented on a change in pull request #1909: [CALCITE-3914] Improve SubsitutionVisitor to consider RexCall of type PLUS and TIMES for canonicalization (Vineet Garg)
URL: https://github.com/apache/calcite/pull/1909#discussion_r406995687
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
 ##########
 @@ -345,13 +345,29 @@ private static RexNode canonizeNode(RexBuilder rexBuilder, RexNode condition) {
     case LESS_THAN_OR_EQUAL:
     case GREATER_THAN_OR_EQUAL: {
       RexCall call = (RexCall) condition;
-      final RexNode left = call.getOperands().get(0);
-      final RexNode right = call.getOperands().get(1);
+      RexNode left = call.getOperands().get(0);
+      left = canonizeNode(rexBuilder, left);
+      RexNode right = call.getOperands().get(1);
+      right = canonizeNode(rexBuilder, right);
+      call = (RexCall) rexBuilder.makeCall(call.getOperator(), left, right);
       if (left.toString().compareTo(right.toString()) <= 0) {
         return call;
 
 Review comment:
   You can return the original call if `left==call.getOperands().get(0) && right==call.getOperands().get(1)`. Below (for + and *), you could check if that is the case too, and return the original call otherwise; it is worth skipping new expression creation in these cases).

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] jcamachor commented on a change in pull request #1909: [CALCITE-3914] Improve SubsitutionVisitor to consider RexCall of type PLUS and TIMES for canonicalization (Vineet Garg)

Posted by GitBox <gi...@apache.org>.
jcamachor commented on a change in pull request #1909: [CALCITE-3914] Improve SubsitutionVisitor to consider RexCall of type PLUS and TIMES for canonicalization (Vineet Garg)
URL: https://github.com/apache/calcite/pull/1909#discussion_r406994488
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
 ##########
 @@ -345,13 +345,29 @@ private static RexNode canonizeNode(RexBuilder rexBuilder, RexNode condition) {
     case LESS_THAN_OR_EQUAL:
     case GREATER_THAN_OR_EQUAL: {
       RexCall call = (RexCall) condition;
-      final RexNode left = call.getOperands().get(0);
-      final RexNode right = call.getOperands().get(1);
+      RexNode left = call.getOperands().get(0);
+      left = canonizeNode(rexBuilder, left);
+      RexNode right = call.getOperands().get(1);
+      right = canonizeNode(rexBuilder, right);
+      call = (RexCall) rexBuilder.makeCall(call.getOperator(), left, right);
       if (left.toString().compareTo(right.toString()) <= 0) {
         return call;
       }
       return RexUtil.invert(rexBuilder, call);
     }
+    case PLUS:
+    case TIMES:
+      RexCall call = (RexCall) condition;
+      RexNode left = call.getOperands().get(0);
+      RexNode right = call.getOperands().get(1);
+      left = canonizeNode(rexBuilder, left);
+      right = canonizeNode(rexBuilder, right);
+
+      if (left.toString().compareTo(right.toString()) <= 0) {
+        return rexBuilder.makeCall(call.getOperator(), left, right);
+      } else {
+        return rexBuilder.makeCall(call.getOperator(), right, left);
 
 Review comment:
   We should introduce an additional check before returning the new swapped expression to verify that the return type of the new call is similar to the return type of the original one (we can do that via `SqlTypeUtil.equalSansNullability`); otherwise, we should not swap. For instance, in Calcite the type inference for + or * will be dependent on the order of the operands. But other systems, e.g., Hive, may have their own implementation and apply different rules for type inference.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] jcamachor commented on a change in pull request #1909: [CALCITE-3914] Improve SubsitutionVisitor to consider RexCall of type PLUS and TIMES for canonicalization (Vineet Garg)

Posted by GitBox <gi...@apache.org>.
jcamachor commented on a change in pull request #1909: [CALCITE-3914] Improve SubsitutionVisitor to consider RexCall of type PLUS and TIMES for canonicalization (Vineet Garg)
URL: https://github.com/apache/calcite/pull/1909#discussion_r406995687
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
 ##########
 @@ -345,13 +345,29 @@ private static RexNode canonizeNode(RexBuilder rexBuilder, RexNode condition) {
     case LESS_THAN_OR_EQUAL:
     case GREATER_THAN_OR_EQUAL: {
       RexCall call = (RexCall) condition;
-      final RexNode left = call.getOperands().get(0);
-      final RexNode right = call.getOperands().get(1);
+      RexNode left = call.getOperands().get(0);
+      left = canonizeNode(rexBuilder, left);
+      RexNode right = call.getOperands().get(1);
+      right = canonizeNode(rexBuilder, right);
+      call = (RexCall) rexBuilder.makeCall(call.getOperator(), left, right);
       if (left.toString().compareTo(right.toString()) <= 0) {
         return call;
 
 Review comment:
   You can return the original call if `left==call.getOperands().get(0) && right==call.getOperands().get(1)`. Below (for + and *), you could check if that is the case too, and return the original call otherwise; it is worth skipping new expression creation in these cases).

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] jcamachor commented on a change in pull request #1909: [CALCITE-3914] Improve SubsitutionVisitor to consider RexCall of type PLUS and TIMES for canonicalization (Vineet Garg)

Posted by GitBox <gi...@apache.org>.
jcamachor commented on a change in pull request #1909: [CALCITE-3914] Improve SubsitutionVisitor to consider RexCall of type PLUS and TIMES for canonicalization (Vineet Garg)
URL: https://github.com/apache/calcite/pull/1909#discussion_r406991290
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
 ##########
 @@ -345,13 +345,29 @@ private static RexNode canonizeNode(RexBuilder rexBuilder, RexNode condition) {
     case LESS_THAN_OR_EQUAL:
     case GREATER_THAN_OR_EQUAL: {
       RexCall call = (RexCall) condition;
-      final RexNode left = call.getOperands().get(0);
-      final RexNode right = call.getOperands().get(1);
+      RexNode left = call.getOperands().get(0);
 
 Review comment:
   nit. L348 and L349 could be merged into a single one. Same below.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] vineetgarg02 commented on a change in pull request #1909: [CALCITE-3914] Improve SubsitutionVisitor to consider RexCall of type PLUS and TIMES for canonicalization (Vineet Garg)

Posted by GitBox <gi...@apache.org>.
vineetgarg02 commented on a change in pull request #1909: [CALCITE-3914] Improve SubsitutionVisitor to consider RexCall of type PLUS and TIMES for canonicalization (Vineet Garg)
URL: https://github.com/apache/calcite/pull/1909#discussion_r406987194
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/plan/SubstitutionVisitor.java
 ##########
 @@ -324,6 +324,8 @@ public static RexNode splitFilter(final RexSimplify simplify,
    */
   private static RexNode canonizeNode(RexBuilder rexBuilder, RexNode condition) {
     switch (condition.getKind()) {
+    case PLUS:
 
 Review comment:
   @jcamachor Thanks for catching this. I have updated the pull request.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [calcite] asfgit closed pull request #1909: [CALCITE-3914] Improve SubsitutionVisitor to consider RexCall of type PLUS and TIMES for canonicalization (Vineet Garg)

Posted by GitBox <gi...@apache.org>.
asfgit closed pull request #1909: [CALCITE-3914] Improve SubsitutionVisitor to consider RexCall of type PLUS and TIMES for canonicalization (Vineet Garg)
URL: https://github.com/apache/calcite/pull/1909
 
 
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services