Package org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators

Source Code of org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POPackageLite

/*
* 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.Iterator;
import java.util.List;

import org.apache.pig.PigException;
import org.apache.pig.backend.executionengine.ExecException;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.POStatus;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.PhysicalOperator;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.Result;
import org.apache.pig.backend.hadoop.executionengine.physicalLayer.plans.PhyPlanVisitor;
import org.apache.pig.data.DataBag;
import org.apache.pig.data.DataType;
import org.apache.pig.data.ReadOnceBag;
import org.apache.pig.data.Tuple;
import org.apache.pig.impl.io.NullableTuple;
import org.apache.pig.impl.plan.NodeIdGenerator;
import org.apache.pig.impl.plan.OperatorKey;
import org.apache.pig.impl.plan.VisitorException;

/**
* This package operator is a specialization
* of POPackage operator used for the specific
* case of the order by query. See JIRA 802
* for more details.
*/
public class POPackageLite extends POPackage {

    /**
     *
     */
    private static final long serialVersionUID = 1L;

    public POPackageLite(OperatorKey k) {
        super(k, -1, null);
    }

    public POPackageLite(OperatorKey k, int rp) {
        super(k, rp, null);
    }

    public POPackageLite(OperatorKey k, List<PhysicalOperator> inp) {
        super(k, -1, inp);
    }

    public POPackageLite(OperatorKey k, int rp, List<PhysicalOperator> inp) {
        super(k, rp, inp);
    }

    /* (non-Javadoc)
     * @see org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POPackage#setNumInps(int)
     */
  @Override
    public void setNumInps(int numInps) {
    if(numInps != 1)
    {
      throw new RuntimeException("POPackageLite can only take 1 input");
    }
        this.numInputs = numInps;
    }
 
    public boolean[] getInner() {
        throw new RuntimeException("POPackageLite does not support getInner operation");
    }

    public void setInner(boolean[] inner) {
        throw new RuntimeException("POPackageLite does not support setInner operation");
    }
   
    /**
     * Make a deep copy of this operator. 
     * @throws CloneNotSupportedException
     */
    @Override
    public POPackageLite clone() throws CloneNotSupportedException {
        POPackageLite clone = (POPackageLite)super.clone();
        clone.inner = null;
        return clone;
    }
   
    /**
     * @return the distinct
     */
    @Override
    public boolean isDistinct() {
        throw new RuntimeException("POPackageLite does not support isDistinct operation");
    }

    /**
     * @param distinct the distinct to set
     */
    @Override
    public void setDistinct(boolean distinct) {
        throw new RuntimeException("POPackageLite does not support setDistinct operation");
    }

    /**
     * @return the isKeyTuple
     */
    public boolean getKeyTuple() {
        return isKeyTuple;
    }

    /**
     * @return the keyAsTuple
     */
    public Tuple getKeyAsTuple() {
        return keyAsTuple;
    }

    /**
     * @return the tupIter
     */
    public Iterator<NullableTuple> getTupIter() {
        return tupIter;
    }

    /**
     * @return the key
     */
    public Object getKey() {
        return key;
    }

    /**
     * Similar to POPackage.getNext except that
     * only one input is expected with index 0
     * and ReadOnceBag is used instead of
     * DefaultDataBag.
     */
    @Override
    public Result getNext(Tuple t) throws ExecException {
        Tuple res;
        //Create numInputs bags
        ReadOnceBag db = null;
        db = new ReadOnceBag(this, tupIter, key);
        if(reporter!=null) reporter.progress();
       
        //Construct the output tuple by appending
        //the key and all the above constructed bags
        //and return it.
        res = mTupleFactory.newTuple(numInputs+1);
        res.set(0,key);
        res.set(1,db);
        detachInput();
        Result r = new Result();
        r.result = res;
        r.returnStatus = POStatus.STATUS_OK;
        return r;
    }
   
    /**
     * Makes use of the superclass method, but this requires
     * an additional parameter key passed by ReadOnceBag.
     * key of this instance will be set to null in detachInput
     * call, but an instance of ReadOnceBag may have the original
     * key that it uses. Therefore this extra argument is taken
     * to temporarily set it before the call to the superclass method
     * and then restore it. 
     */
    public Tuple getValueTuple(NullableTuple ntup, int index, Object key) throws ExecException {
        Object origKey = this.key;
        this.key = key;
        Tuple retTuple = super.getValueTuple(ntup, index);
        this.key = origKey;
        return retTuple;
    }

}
TOP

Related Classes of org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POPackageLite

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.