You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Ziwei Liu (Jira)" <ji...@apache.org> on 2021/12/25 02:48:00 UTC

[jira] [Updated] (CALCITE-4964) reduce recursion when push predicate into case

     [ https://issues.apache.org/jira/browse/CALCITE-4964?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ziwei Liu updated CALCITE-4964:
-------------------------------
    Description: 
I think CaseShuttle has some

CaseShuttle's recursion can be reduced like:
{code:java}
@Override public RexNode visitCall(RexCall call) {
   call = (RexCall) super.visitCall(call);
   if (call instanceof OdpsLambdaRexCall) {
      return call;
   }
   final RexCall old = call;
   call = ReduceExpressionsRule.pushPredicateIntoCase(call);
   if (call == old) {
     return call;
   } else {
      boolean containCase = false;
      List<RexNode> newOps = new ArrayList<>(call.getOperands().size());
      // call will be like case when c1 then f(x1 ...)
      // check whether need push f into x1
      for (int i = 0; i < call.getOperands().size(); i ++) {
         RexNode op = call.getOperands().get(i);
         RexNode newOp = op;
         if (i % 2 == 1 || i == call.getOperands().size() - 1) {
           if (op instanceof RexCall) {
             newOp = ReduceExpressionsRule.pushPredicateIntoCase((RexCall) op);
           }
         }
         if (op != newOp) {
           containCase = true;
         }
         newOps.add(newOp);
       }
       if (!containCase) {
         return call;
       } else {
         return call.clone(call.getType(), newOps);
       }
   }    
} {code}

  was:
CaseShuttle's recursion can be reduced like:
{code:java}
@Override public RexNode visitCall(RexCall call) {
   call = (RexCall) super.visitCall(call);
   if (call instanceof OdpsLambdaRexCall) {
      return call;
   }
   final RexCall old = call;
   call = ReduceExpressionsRule.pushPredicateIntoCase(call);
   if (call == old) {
     return call;
   } else {
      boolean containCase = false;
      List<RexNode> newOps = new ArrayList<>(call.getOperands().size());
      // call will be like case when c1 then f(x1 ...)
      // check whether need push f into x1
      for (int i = 0; i < call.getOperands().size(); i ++) {
         RexNode op = call.getOperands().get(i);
         RexNode newOp = op;
         if (i % 2 == 1 || i == call.getOperands().size() - 1) {
           if (op instanceof RexCall) {
             newOp = ReduceExpressionsRule.pushPredicateIntoCase((RexCall) op);
           }
         }
         if (op != newOp) {
           containCase = true;
         }
         newOps.add(newOp);
       }
       if (!containCase) {
         return call;
       } else {
         return call.clone(call.getType(), newOps);
       }
   }    
} {code}


> reduce recursion when push predicate into case
> ----------------------------------------------
>
>                 Key: CALCITE-4964
>                 URL: https://issues.apache.org/jira/browse/CALCITE-4964
>             Project: Calcite
>          Issue Type: Improvement
>            Reporter: Ziwei Liu
>            Assignee: Ziwei Liu
>            Priority: Major
>
> I think CaseShuttle has some
> CaseShuttle's recursion can be reduced like:
> {code:java}
> @Override public RexNode visitCall(RexCall call) {
>    call = (RexCall) super.visitCall(call);
>    if (call instanceof OdpsLambdaRexCall) {
>       return call;
>    }
>    final RexCall old = call;
>    call = ReduceExpressionsRule.pushPredicateIntoCase(call);
>    if (call == old) {
>      return call;
>    } else {
>       boolean containCase = false;
>       List<RexNode> newOps = new ArrayList<>(call.getOperands().size());
>       // call will be like case when c1 then f(x1 ...)
>       // check whether need push f into x1
>       for (int i = 0; i < call.getOperands().size(); i ++) {
>          RexNode op = call.getOperands().get(i);
>          RexNode newOp = op;
>          if (i % 2 == 1 || i == call.getOperands().size() - 1) {
>            if (op instanceof RexCall) {
>              newOp = ReduceExpressionsRule.pushPredicateIntoCase((RexCall) op);
>            }
>          }
>          if (op != newOp) {
>            containCase = true;
>          }
>          newOps.add(newOp);
>        }
>        if (!containCase) {
>          return call;
>        } else {
>          return call.clone(call.getType(), newOps);
>        }
>    }    
> } {code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)