zoudan commented on code in PR #3247:
URL: https://github.com/apache/calcite/pull/3247#discussion_r1226169010


##########
core/src/main/java/org/apache/calcite/rex/RexSimplify.java:
##########
@@ -672,9 +675,28 @@ private void simplifyAndTerms(List<RexNode> terms, 
RexUnknownAs unknownAs) {
     RexSimplify simplify = this;
     for (int i = 0; i < terms.size(); i++) {
       RexNode t = terms.get(i);
-      if (Predicate.of(t) == null) {
+      Predicate predicate = Predicate.of(t); 
+      if (predicate == null) {
         continue;
       }
+      
+      //add for array-type
+      if (predicate instanceof Comparison) {
+        Comparison cmp = (Comparison) predicate;
+        if (cmp.rexCall != null && 
cmp.rexCall.getKind().equals(SqlKind.ARRAY_VALUE_CONSTRUCTOR)) {

Review Comment:
   `SqlKind` is an enum type, you could use `==`



##########
core/src/main/java/org/apache/calcite/rex/RexSimplify.java:
##########
@@ -2660,6 +2695,24 @@ private Comparison(RexNode ref, SqlKind kind, RexLiteral 
literal) {
             return new Comparison(left, e.getKind(), (RexLiteral) right);
           }
           break;
+        //add for RexCall like "CAST(ARRAY(..., ...))..."
+        case CAST:
+          final RexCall castCall = (RexCall) right;
+          final RexNode castLeft = castCall.getOperands().get(0);
+          switch (castLeft.getKind()) {
+            case ARRAY_VALUE_CONSTRUCTOR:
+              //array-type RexCall --> create a comparison of RexCall
+              if (nodePredicate.test(left)) {
+                return new Comparison(left, e.getKind(), (RexCall) castLeft);
+              }
+          }
+          break;
+        case ARRAY_VALUE_CONSTRUCTOR:
+          //array-type RexCall --> create a comparison of RexCall

Review Comment:
   It is better to reuse the duplicate code.



##########
core/src/main/java/org/apache/calcite/rex/RexSimplify.java:
##########
@@ -2669,10 +2722,28 @@ private Comparison(RexNode ref, SqlKind kind, 
RexLiteral literal) {
             return new Comparison(right, e.getKind().reverse(), (RexLiteral) 
left);
           }
           break;
+        //add for RexCall like "CAST(ARRAY(..., ...))..."
+        case CAST:
+          final RexCall castCall = (RexCall) left;
+          final RexNode castLeft = castCall.getOperands().get(0);
+          switch (castLeft.getKind()) {
+            case ARRAY_VALUE_CONSTRUCTOR:
+              //array-type RexCall --> create a comparison of RexCall
+              if (nodePredicate.test(right)) {
+                return new Comparison(right, e.getKind().reverse(), (RexCall) 
castLeft);
+              }
+          }
+          break;
+        case ARRAY_VALUE_CONSTRUCTOR:
+          //array-type RexCall --> create a comparison of RexCall
+          if (nodePredicate.test(right)) {
+            return new Comparison(right, e.getKind().reverse(), (RexCall) 
left);
+          }
+          break;
         default:
           break;
         }
-        break;
+        break;    

Review Comment:
   Do not add spaces at the end of lines



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to