Package org.apache.pig.impl.io

Examples of org.apache.pig.impl.io.PigNullableWritable


        }
        // ITIterator iti = new TestPackage.ITIterator(db.iterator());
        POPackage pop = new POPackage(new OperatorKey("", r.nextLong()));
        pop.setNumInps(2);
        pop.getPkgr().setInner(inner);
        PigNullableWritable k = HDataType.getWritableComparableTypes(key, keyType);
        pop.attachInput(k, db.iterator());
        if (keyType != DataType.BAG) {
            // test serialization
            NullablePartitionWritable wr;
            if (keyType == DataType.TUPLE) {
                BinSedesTuple tup = (BinSedesTuple) binfactory.newTupleNoCopy(((Tuple) k.getValueAsPigType()).getAll());
                wr = new NullablePartitionWritable(new NullableTuple(tup));
            } else {
                wr = new NullablePartitionWritable(k);
            }
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
View Full Code Here


     * restore it.
     */
    @Override
    public Tuple getValueTuple(PigNullableWritable keyWritable,
            NullableTuple ntup, int index) throws ExecException {
        PigNullableWritable origKey = this.keyWritable;
        this.keyWritable = keyWritable;
        Tuple retTuple = super.getValueTuple(keyWritable, ntup, index);
        this.keyWritable = origKey;
        return retTuple;
    }
View Full Code Here

        Packager pkgr = packagers.get(index);

        // check to see if we need to unwrap the key. The keys may be
        // wrapped inside a tuple by LocalRearrange operator when jobs
        // with different map key types are merged
        PigNullableWritable curKey = keyWritable;
        if (!sameMapKeyType && !inCombiner && isKeyWrapped.get(index)) {
            Tuple tup = (Tuple) keyWritable.getValueAsPigType();
            curKey = HDataType.getWritableComparableTypes(tup.get(0),
                    pkgr.getKeyType());
            curKey.setIndex(origIndex);
        }

        pkgr.attachInput(curKey, bags, readOnce);

        Result res = pkgr.getNext();
        pkgr.detachInput();
        detachInput();

        Tuple tuple = (Tuple)res.result;

        // the object present in the first field
        // of the tuple above is the real data without
        // index information - this is because the
        // package above, extracts the real data out of
        // the PigNullableWritable object - we are going to
        // give this result tuple to a PODemux operator
        // which needs a PigNullableWritable first field so
        // it can figure out the index. Therefore we need
        // to add index to the first field of the tuple.

        Object obj = tuple.get(0);
        if (obj instanceof PigNullableWritable) {
            ((PigNullableWritable)obj).setIndex(origIndex);
        }
        else {
            PigNullableWritable myObj = null;
            if (obj == null) {
                myObj = new NullableUnknownWritable();
                myObj.setNull(true);
            }
            else {
                myObj = HDataType.getWritableComparableTypes(obj, HDataType.findTypeFromNullableWritable(curKey));
            }
            myObj.setIndex(origIndex);
            tuple.set(0, myObj);
        }
        // illustrator markup has been handled by "pkgr"
        return res;
    }
View Full Code Here

    @Override
    public Tuple getValueTuple(PigNullableWritable keyWritable,
            NullableTuple ntup, int origIndex) throws ExecException {
        this.keyWritable = keyWritable;
        int index = origIndex & idxPart;
        PigNullableWritable newKey = keyWritable;
        if (!sameMapKeyType && !inCombiner && isKeyWrapped.get(index)) {                                      
            Tuple tup = (Tuple)this.keyWritable.getValueAsPigType();
            newKey = HDataType.getWritableComparableTypes(tup.get(0), packagers.get(index).getKeyType());
            newKey.setIndex((byte)origIndex);
        }
        return packagers.get(index).getValueTuple(newKey, ntup, origIndex);
    }
View Full Code Here

        }

        while (res.returnStatus == POStatus.STATUS_EOP) {
            boolean hasData = false;
            Object cur = null;
            PigNullableWritable min = null;
            int minIndex = -1;

            try {
                for (int i = 0; i < numInputs; i++) {
                    if (!finished[i]) {
                        hasData = true;
                        cur = readers.get(i).getCurrentKey();
                        if (min == null || comparator.compare(min, cur) > 0) {
                            //Not a deep clone. Writable is referenced.
                            min = ((PigNullableWritable)cur).clone();
                            minIndex = i;
                        }
                    }
                }
            } catch (Exception e) {
                throw new ExecException(e);
            }

            if (!hasData) {
                // For certain operators (such as STREAM), we could still have some work
                // to do even after seeing the last input. These operators set a flag that
                // says all input has been sent and to run the pipeline one more time.
                if (Boolean.valueOf(conf.get(JobControlCompiler.END_OF_INP_IN_MAP, "false"))) {
                    this.parentPlan.endOfAllInput = true;
                }
                return new Result(POStatus.STATUS_EOP, null);
            }

            key = pkgr.getKey(min);
            keyWritable = min;

            try {
                DataBag[] bags = new DataBag[numInputs];
                if (isAccumulative()) {

                    buffer.setCurrentKey(min);
                    buffer.setCurrentKeyIndex(minIndex);
                    for (int i = 0; i < numInputs; i++) {
                        bags[i] = new AccumulativeBag(buffer, i);
                    }

                } else {

                    for (int i = 0; i < numInputs; i++) {

                        DataBag bag = null;

                        if (!finished[i]) {
                            cur = readers.get(i).getCurrentKey();
                            // We need to loop in case of Grouping Comparators
                            while (comparator.compare(min, cur) == 0
                                    && (!min.isNull() || (min.isNull() && i == minIndex))) {
                                Iterable<Object> vals = readers.get(i).getCurrentValues();
                                bag = bags[i] == null ? new InternalCachedBag(numInputs) : bags[i];
                                for (Object val : vals) {
                                    NullableTuple nTup = (NullableTuple) val;
                                    int index = nTup.getIndex();
View Full Code Here

            Iterator<Tuple> its = ((DataBag)res.result).iterator();
            while (its.hasNext()) {
                Tuple result = its.next();
                Byte index = (Byte)result.get(0);

                PigNullableWritable key =
                        HDataType.getWritableComparableTypes(result.get(2), keyType);
                NullableTuple val = new NullableTuple((Tuple)result.get(3));

                NullablePartitionWritable wrappedKey = new NullablePartitionWritable(key);
                wrappedKey.setIndex(index);
View Full Code Here

                while (replReaders.get(inputIdx).next()) {
                    if (getReporter() != null) {
                        getReporter().progress();
                    }

                    PigNullableWritable key = (PigNullableWritable) replReaders.get(inputIdx).getCurrentKey();
                    if (isKeyNull(key.getValueAsPigType())) continue;
                    NullableTuple val = (NullableTuple) replReaders.get(inputIdx).getCurrentValue();

                    // POFRJoin#getValueTuple() is reused to construct valTuple,
                    // and it takes an indexed Tuple as parameter. So we need to
                    // construct one here.
                    Tuple retTuple = mTupleFactory.newTuple(3);
                    retTuple.set(0, key.getIndex());
                    retTuple.set(1, key.getValueAsPigType());
                    retTuple.set(2, val.getValueAsPigType());
                    Tuple valTuple = getValueTuple(lr, retTuple);

                    Tuple keyTuple = mTupleFactory.newTuple(1);
                    keyTuple.set(0, key.getValueAsPigType());
                    if (replicate.get(keyTuple) == null) {
                        replicate.put(keyTuple, new TuplesToSchemaTupleList(1, inputSchemaTupleFactory));
                    }
                    replicate.get(keyTuple).add(valTuple);
                }
View Full Code Here

            switch (res.returnStatus) {
            case POStatus.STATUS_OK:
                if (illustrator == null) {
                    Tuple result = (Tuple) res.result;
                    Byte index = (Byte) result.get(0);
                    PigNullableWritable key = HDataType.getWritableComparableTypes(result.get(1), keyType);
                    NullableTuple val = new NullableTuple((Tuple)result.get(2));

                    // Both the key and the value need the index.  The key needs it so
                    // that it can be sorted on the index in addition to the key
                    // value.  The value needs it so that POPackage can properly
                    // assign the tuple to its slot in the projection.
                    key.setIndex(index);
                    val.setIndex(index);
                    writer.write(key, val);
                } else {
                    illustratorMarkup(res.result, res.result, 0);
                }
View Full Code Here

        }
        // ITIterator iti = new TestPackage.ITIterator(db.iterator());
        POPackage pop = new POPackage(new OperatorKey("", r.nextLong()));
        pop.setNumInps(2);
        pop.setInner(inner);
        PigNullableWritable k = HDataType.getWritableComparableTypes(key, keyType);
        pop.attachInput(k, db.iterator());
        if (keyType != DataType.BAG) {
            // test serialization
            NullablePartitionWritable wr;
            if (keyType == DataType.TUPLE) {
                BinSedesTuple tup = (BinSedesTuple) binfactory.newTupleNoCopy(((Tuple) k.getValueAsPigType()).getAll());
                wr = new NullablePartitionWritable(new NullableTuple(tup));
            } else {
                wr = new NullablePartitionWritable(k);
            }
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
View Full Code Here

        POPackage pack = packages.get(index);
       
        // check to see if we need to unwrap the key. The keys may be
        // wrapped inside a tuple by LocalRearrange operator when jobs 
        // with different map key types are merged
        PigNullableWritable curKey = myKey;
        if (!sameMapKeyType && !inCombiner && isKeyWrapped.get(index)) {                                      
            Tuple tup = (Tuple)myKey.getValueAsPigType();
            curKey = HDataType.getWritableComparableTypes(tup.get(0), pack.getKeyType());
            curKey.setIndex(origIndex);
        }
           
        pack.attachInput(curKey, tupIter);

        Result res = pack.getNextTuple();
        pack.detachInput();
       
        Tuple tuple = (Tuple)res.result;

        // the object present in the first field
        // of the tuple above is the real data without
        // index information - this is because the
        // package above, extracts the real data out of
        // the PigNullableWritable object - we are going to
        // give this result tuple to a PODemux operator
        // which needs a PigNullableWritable first field so
        // it can figure out the index. Therefore we need
        // to add index to the first field of the tuple.
               
        Object obj = tuple.get(0);
        if (obj instanceof PigNullableWritable) {
            ((PigNullableWritable)obj).setIndex(origIndex);
        }
        else {
            PigNullableWritable myObj = null;
            if (obj == null) {
                myObj = new NullableUnknownWritable();
                myObj.setNull(true);
            }
            else {
                myObj = HDataType.getWritableComparableTypes(obj, HDataType.findTypeFromNullableWritable(curKey));
            }
            myObj.setIndex(origIndex);
            tuple.set(0, myObj);
        }
        // illustrator markup has been handled by "pack"
        return res;
    }
View Full Code Here

TOP

Related Classes of org.apache.pig.impl.io.PigNullableWritable

Copyright © 2018 www.massapicom. 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.