Examples of NullableTuple


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

            case POStatus.STATUS_EOP:
                break;
            }
        }
       
        NullableTuple it = null;
       
        // If we see a new NullableTupleIterator, materialize n-1 inputs, construct ForEach input
        // tuple res = (key, input#1, input#2....input#n), the only missing value is input#n,
        // we will get input#n one tuple a time, fill in res, feed to ForEach.
        // After this block, we have the first tuple of input#n in hand (kept in variable it)
        if (newKey)
        {
            lastInputTuple = false;
            //Put n-1 inputs into bags
            dbs = new DataBag[numInputs];
            for (int i = 0; i < numInputs - 1; i++) {
                dbs[i] = useDefaultBag ? BagFactory.getInstance().newDefaultBag()
                // In a very rare case if there is a POStream after this
                // POJoinPackage in the pipeline and is also blocking the pipeline;
                // constructor argument should be 2 * numInputs. But for one obscure
                // case we don't want to pay the penalty all the time.       
                        : new InternalCachedBag(numInputs-1);                   
            }
            // For last bag, we always use NonSpillableBag.
            dbs[lastBagIndex] = new NonSpillableDataBag((int)chunkSize);
           
            //For each Nullable tuple in the input, put it
            //into the corresponding bag based on the index,
            // except for the last input, which we will stream
            // The tuples will arrive in the order of the index,
            // starting from index 0 and such that all tuples for
            // a given index arrive before a tuple for the next
            // index does.
            while (tupIter.hasNext()) {
                it = tupIter.next();
                int itIndex = it.getIndex();
                if (itIndex!= numInputs - 1)
                {
                    dbs[itIndex].add(getValueTuple(it, itIndex));
                }
                else
                {
                    lastInputTuple = true;
                    break;
                }
                if(reporter!=null) reporter.progress();
            }
            // If we don't have any tuple for input#n
            // we do not need any further process, return EOP
            if (!lastInputTuple)
            {
                // we will return at this point because we ought
                // to be having a flatten on this last input
                // and we have an empty bag which should result
                // in this key being taken out of the output
                newKey = true;
                return eopResult;
            }
           
            res = mTupleFactory.newTuple(numInputs+1);
            for (int i = 0; i < dbs.length; i++)
                res.set(i+1,dbs[i]);

            res.set(0,key);
            // if we have an inner anywhere and the corresponding
            // bag is empty, we can just return
            for (int i = 0; i < dbs.length - 1; i++) {
                if(inner[i]&&dbs[i].size()==0){
                    detachInput();
                    return eopResult;
                }
            }
            newKey = false;
           
      // set up the bag with last input to contain
      // a chunk of CHUNKSIZE values OR the entire bag if
      // it has less than CHUNKSIZE values - the idea is in most
      // cases the values are > CHUNKSIZE in number and in
      // those cases we will be sending the last bag
      // as a set of smaller chunked bags thus holding lesser
      // in memory
     
      // the first tuple can be directly retrieved from "it"
      dbs[lastBagIndex].add(getValueTuple(it, it.getIndex()));
      for(int i = 0; i < chunkSize -1 && tupIter.hasNext(); i++) {
          it = tupIter.next();
          dbs[lastBagIndex].add(getValueTuple(it, it.getIndex()));
      }

      // Attach the input to forEach
            forEach.attachInput(res);
           
            // pull output tuple from ForEach
            Result forEachResult = forEach.getNext(t1);
            {
                switch (forEachResult.returnStatus)
                {
                case POStatus.STATUS_OK:
                case POStatus.STATUS_NULL:
                case POStatus.STATUS_ERR:
                    return forEachResult;
                case POStatus.STATUS_EOP:
                    break;
                }
            }
        }
       
        // Keep attaching input tuple to ForEach, until:
        // 1. We can initialize ForEach.getNext();
        // 2. There is no more input#n
        while (true)
        {
            if (tupIter.hasNext()) {
                // try setting up a bag of CHUNKSIZE OR
                // the remainder of the bag of last input
                // (if < CHUNKSIZE) to foreach
                dbs[lastBagIndex].clear(); // clear last chunk
                for(int i = 0; i < chunkSize && tupIter.hasNext(); i++) {
                    it = tupIter.next();
                    dbs[lastBagIndex].add(getValueTuple(it, it.getIndex()));
                }
            }
            else
            // if we do not have any more tuples for input#n, return EOP
            {
View Full Code Here

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

       
        // For each indexed tup in the inp, split them up and place their
        // fields into the proper bags.  If the given field isn't a bag, just
        // set the value as is.
        while (tupIter.hasNext()) {
            NullableTuple ntup = tupIter.next();
            Tuple tup = (Tuple)ntup.getValueAsPigType();
           
            int tupIndex = 0; // an index for accessing elements from
                              // the value (tup) that we have currently
            for(int i = 0; i < mBags.length; i++) {
                Integer keyIndex = keyLookup.get(i);
View Full Code Here

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

                }                              
                //For each indexed tup in the inp, sort them
                //into their corresponding bags based
                //on the index
                while (tupIter.hasNext()) {
                    NullableTuple ntup = tupIter.next();
                    int index = ntup.getIndex();
                    Tuple copy = getValueTuple(ntup, index)
                   
                    if (numInputs == 1) {
                       
                        // this is for multi-query merge where
View Full Code Here

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

            }
                       
            key = currKey;     
            for(int i=0; i<batchSize; i++) {
                if (iter.hasNext()) {
                     NullableTuple ntup = iter.next();
                     int index = ntup.getIndex();
                     Tuple copy = getValueTuple(ntup, index);               
                     if (numInputs == 1) {
                           
                            // this is for multi-query merge where
                            // the numInputs is always 1, but the index
View Full Code Here

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

          
        case DataType.LONG:
            return new NullableLongWritable((Long)o);
         
        case DataType.TUPLE:
            return new NullableTuple((Tuple)o);
        
        case DataType.MAP: {
            int errCode = 1068;
            String msg = "Using Map as key not supported.";
            throw new ExecException(msg, errCode, PigException.INPUT);
        }

        case DataType.NULL:
            switch (keyType) {
            case DataType.BAG:
                NullableBag nbag = new NullableBag();
                nbag.setNull(true);
                return nbag;
            case DataType.BOOLEAN:
                NullableBooleanWritable nboolWrit = new NullableBooleanWritable();
                nboolWrit.setNull(true);
                return nboolWrit;
            case DataType.BYTEARRAY:
                NullableBytesWritable nBytesWrit = new NullableBytesWritable();
                nBytesWrit.setNull(true);
                return nBytesWrit;
            case DataType.CHARARRAY:
                NullableText nStringWrit = new NullableText();
                nStringWrit.setNull(true);
                return nStringWrit;
            case DataType.DOUBLE:
                NullableDoubleWritable nDoubleWrit = new NullableDoubleWritable();
                nDoubleWrit.setNull(true);
                return nDoubleWrit;
            case DataType.FLOAT:
                NullableFloatWritable nFloatWrit = new NullableFloatWritable();
                nFloatWrit.setNull(true);
                return nFloatWrit;
            case DataType.INTEGER:
                NullableIntWritable nIntWrit = new NullableIntWritable();
                nIntWrit.setNull(true);
                return nIntWrit;
            case DataType.LONG:
                NullableLongWritable nLongWrit = new NullableLongWritable();
                nLongWrit.setNull(true);
                return nLongWrit;
            case DataType.TUPLE:
                NullableTuple ntuple = new NullableTuple();
                ntuple.setNull(true);
                return ntuple;
            case DataType.MAP: {
                int errCode = 1068;
                String msg = "Using Map as key not supported.";
                throw new ExecException(msg, errCode, PigException.INPUT);
View Full Code Here

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

            return rc;
        }

        @Override
        public int compare(Object o1, Object o2) {
            NullableTuple nt1 = (NullableTuple) o1;
            NullableTuple nt2 = (NullableTuple) o2;
            int rc = 0;

            // if either are null, handle differently
            if (!nt1.isNull() && !nt2.isNull()) {
                rc = compareTuple((Tuple) nt1.getValueAsPigType(), (Tuple) nt2.getValueAsPigType());
            } else {
                // for sorting purposes two nulls are equal
                if (nt1.isNull() && nt2.isNull())
                    rc = 0;
                else if (nt1.isNull())
                    rc = -1;
                else
                    rc = 1;
View Full Code Here

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

        comparator.setConf(jobConf);
        oldComparator.setConf(jobConf);
        list = Arrays.<Object> asList(1f, 2, 3.0, 4l, (byte) 5, true,
                new DataByteArray(new byte[] { 0x10, 0x2a, 0x5e }), "hello world!",
                tf.newTuple(Arrays.<Object> asList(8.0, 9f, 10l, 11)));
        prototype = new NullableTuple(tf.newTuple(list));
        baos1.reset();
        baos2.reset();
    }
View Full Code Here

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

        baos2.reset();
    }

    @Test
    public void testCompareEquals() throws IOException {
        NullableTuple t = new NullableTuple(tf.newTuple(list));
        int res = compareHelper(prototype, t, comparator);
        assertEquals(Math.signum(prototype.compareTo(t)), Math.signum(res), 0);
        assertTrue(res == 0);
    }
View Full Code Here

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

    }

    @Test
    public void testCompareFloat() throws IOException {
        list.set(0, (Float) list.get(0) - 1);
        NullableTuple t = new NullableTuple(tf.newTuple(list));
        int res = compareHelper(prototype, t, comparator);
        assertEquals(Math.signum(prototype.compareTo(t)), Math.signum(res), 0);
        assertTrue(res > 0);
    }
View Full Code Here

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

    }

    @Test
    public void testCompareInt() throws IOException {
        list.set(1, (Integer) list.get(1) + 1);
        NullableTuple t = new NullableTuple(tf.newTuple(list));
        int res = compareHelper(prototype, t, comparator);
        assertEquals(Math.signum(prototype.compareTo(t)), Math.signum(res), 0);
        assertTrue(res < 0);
    }
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.