Package org.apache.pig.data

Examples of org.apache.pig.data.TupleFactory


            cols.add(j);
            cols.add(j+1);
            proj.setColumns(cols);

            res = proj.getNext();
          TupleFactory tupleFactory = TupleFactory.getInstance();
          ArrayList<Object> objList = new ArrayList<Object>();
            objList.add(t.get(j));
            objList.add(t.get(j+1));
        Tuple expectedResult = tupleFactory.newTuple(objList);
            assertEquals(POStatus.STATUS_OK, res.returnStatus);
            assertEquals(expectedResult, res.result);
            cols.clear();
        }
    }
View Full Code Here


            cols.add(j+1);
            proj.setColumns(cols);
            res = proj.getNext(t);
            if (res.returnStatus == POStatus.STATUS_EOP)
                break;
          TupleFactory tupleFactory = TupleFactory.getInstance();
          ArrayList<Object> objList = new ArrayList<Object>();
            objList.add(t.get(j));
            objList.add(t.get(j+1));
        Tuple expectedResult = tupleFactory.newTuple(objList);
            assertEquals(POStatus.STATUS_OK, res.returnStatus);
            assertEquals(expectedResult, res.result);
            ++j;
            cols.clear();
        }
View Full Code Here

    }
   
    static public class MyBagFunction extends EvalFunc<DataBag>{
        @Override
        public DataBag exec(Tuple input) throws IOException {
            TupleFactory tf = TupleFactory.getInstance();
            DataBag output = BagFactory.getInstance().newDefaultBag();
            output.add(tf.newTuple("a"));
            output.add(tf.newTuple("a"));
            output.add(tf.newTuple("a"));
            return output;
           
        }
View Full Code Here

    static public class MapUDF extends EvalFunc<Map<String, Object>> {
        @Override
        public Map<String, Object> exec(Tuple input) throws IOException {

            TupleFactory tupleFactory = TupleFactory.getInstance();
            ArrayList<Object> objList = new ArrayList<Object>();
            objList.add(new Integer(1));
            objList.add(new Double(1.0));
            objList.add(new Float(1.0));
            objList.add(new String("World!"));
            Tuple tuple = tupleFactory.newTuple(objList);

            BagFactory bagFactory = BagFactory.getInstance();
            DataBag bag = bagFactory.newDefaultBag();
            bag.add(tuple);
View Full Code Here

    }
   
    static public class MyBagFunction extends EvalFunc<DataBag>{
        @Override
        public DataBag exec(Tuple input) throws IOException {
            TupleFactory tf = TupleFactory.getInstance();
            DataBag output = BagFactory.getInstance().newDefaultBag();
            output.add(tf.newTuple("a"));
            output.add(tf.newTuple("a"));
            output.add(tf.newTuple("a"));
            return output;
        }
View Full Code Here

    static public class MapUDF extends EvalFunc<Map<String, Object>> {
        @Override
        public Map<String, Object> exec(Tuple input) throws IOException {

            TupleFactory tupleFactory = TupleFactory.getInstance();
            ArrayList<Object> objList = new ArrayList<Object>();
            objList.add(new Integer(1));
            objList.add(new Double(1.0));
            objList.add(new Float(1.0));
            objList.add(new String("World!"));
            Tuple tuple = tupleFactory.newTuple(objList);

            BagFactory bagFactory = BagFactory.getInstance();
            DataBag bag = bagFactory.newDefaultBag();
            bag.add(tuple);
View Full Code Here

     * @return - Tuple appended with special marker string column, num-rows column
     * @throws ExecException
     */
    private Tuple createNumRowTuple(Tuple sample) throws ExecException {
        int sz = (sample == null) ? 0 : sample.size();
        TupleFactory factory = TupleFactory.getInstance();      
        Tuple t = factory.newTuple(sz + 2);
        if (sample != null) {
            for(int i=0; i<sample.size(); i++){
                t.set(i, sample.get(i));
            }
View Full Code Here

        Util.deleteFile(cluster, "testSFPig-output.txt");
    }
   
    @Test
    public void testTOKENIZE() throws Exception {
        TupleFactory tf = TupleFactory.getInstance();
        Tuple t1 = tf.newTuple(1);
        t1.set(0, "123 456\"789");
        Tuple t2 = tf.newTuple(1);
        t2.set(0, null);
        Tuple t3 = tf.newTuple(0);
       
        TOKENIZE f = new TOKENIZE();
        DataBag b = f.exec(t1);
        assertTrue(b.size()==3);
        Iterator<Tuple> i = b.iterator();
View Full Code Here

    @Test
    public void testDIFF() throws Exception {
        // Test it in the case with two bags.
        BagFactory bf = BagFactory.getInstance();
        TupleFactory tf = TupleFactory.getInstance();

        DataBag b1 = bf.newDefaultBag();
        DataBag b2 = bf.newDefaultBag();
        for (int i = 0; i < 10; i++) b1.add(tf.newTuple(new Integer(i)));
        for (int i = 0; i < 10; i += 2) b2.add(tf.newTuple(new Integer(i)));
        Tuple t = tf.newTuple(2);
        t.set(0, b1);
        t.set(1, b2);
        DIFF d = new DIFF();
        DataBag result = d.exec(t);

        assertEquals(5, result.size());
        Iterator<Tuple> i = result.iterator();
        int[] values = new int[5];
        for (int j = 0; j < 5; j++) values[j] = (Integer)i.next().get(0);
        Arrays.sort(values);
        for (int j = 1; j < 10; j += 2) assertEquals(j, values[j/2]);

        // Test it in the case of two objects that are equals
        t = tf.newTuple(2);
        t.set(0, new Integer(1));
        t.set(1, new Integer(1));
        result = d.exec(t);
        assertEquals(0, result.size());

        // Test it in the case of two objects that are not equal
        t = tf.newTuple(2);
        t.set(0, new Integer(1));
        t.set(1, new Integer(2));
        result = d.exec(t);
        assertEquals(2, result.size());
    }
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    @Test
    public void testBagOfAnnotationMerge() throws IOException {
        TupleFactory tf = TupleFactory.getInstance();
        DefaultDataBag textBag = new DefaultDataBag();
        DefaultDataBag beginBag = new DefaultDataBag();
        DefaultDataBag endBag = new DefaultDataBag();
        DefaultDataBag typeBag = new DefaultDataBag();

        textBag.add(tf.newTupleNoCopy(Arrays.asList(JOHN_SENTENCE)));
        beginBag.add(tf.newTupleNoCopy(Arrays.asList(0)));
        endBag.add(tf.newTupleNoCopy(Arrays.asList(10)));
        typeBag.add(tf.newTupleNoCopy(Arrays.asList("person")));

        textBag.add(tf.newTupleNoCopy(Arrays.asList(JOHN_SENTENCE)));
        beginBag.add(tf.newTupleNoCopy(Arrays.asList(19)));
        endBag.add(tf.newTupleNoCopy(Arrays.asList(36)));
        typeBag.add(tf.newTupleNoCopy(Arrays.asList("organization")));

        // all bags
        Tuple input = tf.newTupleNoCopy(Arrays.asList(textBag, beginBag,
                endBag, typeBag));
        String merged = merger.exec(input);
        assertEquals("<START:person> John Smith <END> works"
                + " at <START:organization> Smith Consulting <END> .", merged);

        // all literals
        input = tf.newTupleNoCopy(Arrays.asList(JOHN_SENTENCE, 0, 10, "person"));
        merged = merger.exec(input);
        assertEquals(
                "<START:person> John Smith <END> works at Smith Consulting .",
                merged);

        // bags without types
        input = tf.newTupleNoCopy(Arrays.asList(textBag, beginBag, endBag));
        merged = merger.exec(input);
        assertEquals(
                "<START> John Smith <END> works at <START> Smith Consulting <END> .",
                merged);

        // bags with fixed type
        input = tf.newTupleNoCopy(Arrays.asList(textBag, beginBag, endBag,
                "entity"));
        merged = merger.exec(input);
        assertEquals("<START:entity> John Smith <END> works at"
                + " <START:entity> Smith Consulting <END> .", merged);
    }
View Full Code Here

TOP

Related Classes of org.apache.pig.data.TupleFactory

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.