Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-4964

Reduce recursion when push predicate into CASE

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • None
    • None

    Description

      I think CaseShuttle do not need a loop of for(;; ).When a predicate is pushed into case, we only need to check the new RexCall whether need to push predicate into the child operand, not need to do a new recursion.

      So I think CaseShuttle can be reduced like:

      @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);
             }
         }    
      } 

      Attachments

        Issue Links

          Activity

            People

              Ziwei Liu Ziwei Liu
              Ziwei Liu Ziwei Liu
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated: