Examples of PigNullableWritable


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

        tupleValIdx--;
      } else {
        partitionIndex = (Integer)tuple.get(1);
      }

            PigNullableWritable key =
                HDataType.getWritableComparableTypes(tuple.get(tupleKeyIdx), DataType.TUPLE);

      NullablePartitionWritable wrappedKey = new NullablePartitionWritable(key);
      //key.setIndex(index);
      //NullableTuple wrappedKey = new NullableTuple((Tuple)tuple);
View Full Code Here

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

    @Override
    public int getPartition(PigNullableWritable key, Writable value,
            int numPartitions) {
        try {
            Tuple t = (Tuple)key.getValueAsPigType();
            PigNullableWritable realKey = HDataType.getWritableComparableTypes(t.get(0), kt);
            return super.getPartition(realKey, value, numPartitions);
        } catch (ExecException e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

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

        @SuppressWarnings("unchecked")
    @Override
        public int compare(WritableComparable a, WritableComparable b)
        {
            PigNullableWritable wa = (PigNullableWritable)a;
            PigNullableWritable wb = (PigNullableWritable)b;
            if ((wa.getIndex() & PigNullableWritable.mqFlag) != 0) { // this is a multi-query index
                if ((wa.getIndex() & PigNullableWritable.idxSpace) < (wb.getIndex() & PigNullableWritable.idxSpace)) return -1;
                else if ((wa.getIndex() & PigNullableWritable.idxSpace) > (wb.getIndex() & PigNullableWritable.idxSpace)) return 1;
                // If equal, we fall through
            }

            // wa and wb are guaranteed to be not null, POLocalRearrange will create a tuple anyway even if main key and secondary key
            // are both null; however, main key can be null, we need to check for that using the same logic we have in PigNullableWritable
            Object valuea = null;
            Object valueb = null;
            try {
                // Get the main key from compound key
                valuea = ((Tuple)wa.getValueAsPigType()).get(0);
                valueb = ((Tuple)wb.getValueAsPigType()).get(0);
            } catch (ExecException e) {
                throw new RuntimeException("Unable to access tuple field", e);
            }
            if (!wa.isNull() && !wb.isNull()) {

                int result = DataType.compare(valuea, valueb);

                // If any of the field inside tuple is null, then we do not merge keys
                // See PIG-927
                if (result == 0 && valuea instanceof Tuple && valueb instanceof Tuple)
                {
                    try {
                        for (int i=0;i<((Tuple)valuea).size();i++)
                            if (((Tuple)valueb).get(i)==null)
                                return (wa.getIndex()&PigNullableWritable.idxSpace) - (wb.getIndex()&PigNullableWritable.idxSpace);
                    } catch (ExecException e) {
                        throw new RuntimeException("Unable to access tuple field", e);
                    }
                }
                return result;
            } else if (valuea==null && valueb==null) {
                // If they're both null, compare the indicies
                if ((wa.getIndex() & PigNullableWritable.idxSpace) < (wb.getIndex() & PigNullableWritable.idxSpace)) return -1;
                else if ((wa.getIndex() & PigNullableWritable.idxSpace) > (wb.getIndex() & PigNullableWritable.idxSpace)) return 1;
                else return 0;
            }
            else if (valuea==null) return -1;
            else return 1;
        }
View Full Code Here

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

        @Override
        public void collect(Context oc, Tuple tuple)
                throws InterruptedException, IOException {

            Byte index = (Byte)tuple.get(0);
            PigNullableWritable key =
                HDataType.getWritableComparableTypes(tuple.get(1), keyType);
            NullableTuple val = new NullableTuple((Tuple)tuple.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);

            oc.write(key, val);
        }
View Full Code Here

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

                keyTuple = tuple.get(1);
            }


            Byte index = (Byte)tuple.get(0);
            PigNullableWritable key =
                HDataType.getWritableComparableTypes(keyTuple, DataType.TUPLE);
            NullableTuple val = new NullableTuple((Tuple)tuple.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);

            oc.write(key, val);
        }
View Full Code Here

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

                tupleValIdx--;
            } else {
                partitionIndex = (Integer)tuple.get(1);
            }

            PigNullableWritable key =
                HDataType.getWritableComparableTypes(tuple.get(tupleKeyIdx), keyType);

            NullablePartitionWritable wrappedKey = new NullablePartitionWritable(key);

            NullableTuple val = new NullableTuple((Tuple)tuple.get(tupleValIdx));
View Full Code Here

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

        Pair <Integer, Integer> indexes;
        Integer curIndex = -1;
        Tuple keyTuple = tf.newTuple(1);

        // extract the key from nullablepartitionwritable
        PigNullableWritable key = ((NullablePartitionWritable) wrappedKey).getKey();

        try {
            keyTuple.set(0, key.getValueAsPigType());
        } catch (ExecException e) {
            return -1;
        }

        // if the key is not null and key
        if (key instanceof NullableTuple && key.getValueAsPigType() != null) {
            keyTuple = (Tuple)key.getValueAsPigType();
        }

        // if the partition file is empty, use numPartitions
        totalReducers = (totalReducers > 0) ? totalReducers : numPartitions;
View Full Code Here

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

            convertToArray(quantilesList);
            long i=-1;
            Map<PigNullableWritable,CountingMap<Integer>> contribs = new HashMap<PigNullableWritable, CountingMap<Integer>>();
            for (Tuple it : samples){
                ++i;
                PigNullableWritable sample = getPigNullableWritable(it);
                int partInd = new Long(i/toSkip).intValue(); // which partition
                if(partInd==numQuantiles) break;
                // the quantiles array has the element from the sample which is the
                // last element for a given partition. For example: if numQunatiles
                // is 5 and number of samples is 100, then toSkip = 20
                // quantiles[0] = sample[19] // the 20th element
                // quantiles[1] = sample[39] // the 40th element
                // and so on. For any element in the sample between 0 and 19, partInd
                // will be 0. We want to check if a sample element which is
                // present between 0 and 19 and is also the 19th (quantiles[0] element).
                // This would mean that element might spread over the 0th and 1st
                // partition. We are looking for contributions to a partition
                // from such elements.
               
                // First We only check for sample elements in partitions other than the last one
                // < numQunatiles -1 (partInd is 0 indexed).
                if(partInd<numQuantiles-1 && areEqual(sample,quantiles[partInd])){
                    if(!contribs.containsKey(sample)){
                        CountingMap<Integer> cm = new CountingMap<Integer>();
                        cm.put(partInd, 1);
                        contribs.put(sample, cm);
                    }
                    else
                        contribs.get(sample).put(partInd, 1);
                }
                else{
                    // we are either in the last partition (last quantile)
                    // OR the sample element we are currently processing is not
                    // the same as the element in the quantile array for this partition
                    // if we haven't seen this sample item earlier, this is not an
                    // element which crosses partitions - so ignore
                    if(!contribs.containsKey(sample))
                        continue;
                    else
                        // we have seen this sample before (in a previous partInd),
                        // add to the contribution associated with this sample - if we had
                        // not seen this sample in a previous partInd, then we have not
                        // had this in the contribs map! (because of the if above).This
                        // sample can either go to the previous partInd or this partInd
                        // in the final sort reduce stage. That is where the amount of
                        // contribution to each partInd will matter and influence the choice.
                        contribs.get(sample).put(partInd, 1);
                }
            }
            for(Entry<PigNullableWritable, CountingMap<Integer>> ent : contribs.entrySet()){
                PigNullableWritable key = ent.getKey(); // sample item which repeats
               
                // this map will have the contributions of the sample item to the different partitions
                CountingMap<Integer> value = ent.getValue();
               
                long total = value.getTotalCount();
View Full Code Here

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

            Mapper<Text, Tuple, PigNullableWritable, Writable> {

        @Override
        public void collect(OutputCollector<PigNullableWritable, Writable> oc, Tuple tuple) throws ExecException, IOException {
            Byte index = (Byte)tuple.get(0);
            PigNullableWritable key =
                HDataType.getWritableComparableTypes(tuple.get(1), keyType);
            NullableTuple val = new NullableTuple((Tuple)tuple.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);
            oc.collect(key, val);
        }
View Full Code Here

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

                keyTuple = tuple.get(1);
            }
           

            Byte index = (Byte)tuple.get(0);
            PigNullableWritable key =
                HDataType.getWritableComparableTypes(keyTuple, DataType.TUPLE);
            NullableTuple val = new NullableTuple((Tuple)tuple.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);
            oc.collect(key, val);
        }
View Full Code Here
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.