Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
   *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators;
 
 import java.util.List;
 
A specialized local rearrange operator which behaves like the regular local rearrange in the getNext() as far as getting its input and constructing the "key" out of the input. It then returns a tuple with two fields - the key in the first position and the "value" inside a bag in the second position. This output format resembles the format out of a Package. This output will feed to a foreach which expects this format.
 
 public class POPreCombinerLocalRearrange extends PhysicalOperator {
     private static final Log log = LogFactory.getLog(POPreCombinerLocalRearrange.class);
 
     protected static final long serialVersionUID = 1L;
 
     protected static final TupleFactory mTupleFactory = TupleFactory.getInstance();
     protected static BagFactory mBagFactory = BagFactory.getInstance();
 
     private static final Result ERR_RESULT = new Result();
 
     protected List<PhysicalPlanplans;
 
     protected List<ExpressionOperatorleafOps;
 
     protected byte keyType;
 
         this(k, -1, null);
     }
 
     public POPreCombinerLocalRearrange(OperatorKey kint rp) {
         this(krpnull);
     }
 
         this(k, -1, inp);
     }
 
     public POPreCombinerLocalRearrange(OperatorKey kint rpList<PhysicalOperatorinp) {
         super(krpinp);
          = new ArrayList<ExpressionOperator>();
     }
 
     @Override
     public void visit(PhyPlanVisitor vthrows VisitorException {
         v.visitPreCombinerLocalRearrange(this);
     }
 
     @Override
     public String name() {
         return getAliasString() + "Pre Combiner Local Rearrange" + "["
                 + DataType.findTypeName() + "]" + "{"
                 + DataType.findTypeName() + "} - " + .toString();
     }
 
     @Override
     public boolean supportsMultipleInputs() {
         return false;
     }
    @Override
    public boolean supportsMultipleOutputs() {
        return false;
    }

    
Overridden since the attachment of the new input should cause the old processing to end.
    @Override
    public void attachInput(Tuple t) {
        super.attachInput(t);
    }

    
Calls getNext on the generate operator inside the nested physical plan. Converts the generated tuple into the proper format, i.e, (key,indexedTuple(value))
    @Override
    public Result getNextTuple() throws ExecException {
        Result inp = null;
        Result res = ;
        while (true) {
            inp = processInput();
            if (inp.returnStatus == . || inp.returnStatus == .) {
                break;
            }
            if (inp.returnStatus == .) {
                continue;
            }
            for (PhysicalPlan ep : ) {
                ep.attachInput((Tuple)inp.result);
            }
            List<ResultresLst = new ArrayList<Result>();
            for (ExpressionOperator op : ){
                switch(op.getResultType()){
                case .:
                case .:
                case .:
                case .:
                case .:
                case .:
                case .:
                case .:
                case .:
                case .:
                case .:
                case .:
                case .:
                    res = op.getNext(op.getResultType());
                    break;
                default:
                    .error("Invalid result type: "
                            + DataType.findType(op.getResultType()));
                    break;
                }
                // allow null as group by key
                if (res.returnStatus != .
                        && res.returnStatus != .) {
                    return new Result();
                }
                resLst.add(res);
            }
            res.result = constructLROutput(resLst,(Tuple)inp.result);
            res.returnStatus = .;
            return res;
        }
        return inp;
    }
    protected Tuple constructLROutput(List<ResultresLstTuple valuethrows ExecException{
        //Construct key
        Object key;
        if(resLst.size()>1){
            Tuple t = .newTuple(resLst.size());
            int i=-1;
            for(Result res : resLst) {
                t.set(++ires.result);
            }
            key = t;
        }
        else{
            key = resLst.get(0).;
        }
        Tuple output = .newTuple(2);
        output.set(0, key);
        // put the value in a bag so that the initial
        // version of the Algebraics will get a bag as
        // they would expect.
        DataBag bg = new SingleTupleBag(value);
        output.set(1, bg);
        return output;
    }
    public byte getKeyType() {
        return ;
    }
    public void setKeyType(byte keyType) {
        this. = keyType;
    }
    public List<PhysicalPlangetPlans() {
        return ;
    }
    public void setPlans(List<PhysicalPlanplans) {
        this. = plans;
        .clear();
        for (PhysicalPlan plan : plans) {
            ExpressionOperator leaf = (ExpressionOperator)plan.getLeaves().get(0);
            .add(leaf);
        }
    }
    @Override
    public Tuple illustratorMarkup(Object inObject outint eqClassIndex) {
        return null;
    }
New to GrepCode? Check out our FAQ X