Package org.apache.pig.data

Examples of org.apache.pig.data.TupleFactory


     
    }
   
    prj.setResultType(DataType.BYTEARRAY);
   
    TupleFactory tf = TupleFactory.getInstance();
   
    {
      Tuple t = tf.newTuple();
      t.append(new DataByteArray((new Integer(r.nextInt())).toString().getBytes()));
      plan.attachInput(t);
      if(t.get(0) == null) {
       
        DataByteArray result = (DataByteArray) op.getNext((String) null).result;
View Full Code Here


  public void testRecordMerger() {
    RecordMerger func = new RecordMerger();

    try {
      Map in = new HashMap<String, String>();
      TupleFactory tf = TupleFactory.getInstance();

      in.put("A", new  DataByteArray("100"));
      in.put("B", new  DataByteArray("200"));
      in.put("C", new  DataByteArray("300"));
     
      Map in2 = new HashMap<String, String>();
     
      in2.put("D", new  DataByteArray("400"));
      in2.put("E", new  DataByteArray("500"));
     
      DataBag bg =  DefaultBagFactory.getInstance().newDefaultBag();
      bg.add(tf.newTuple(in));
      bg.add(tf.newTuple(in2));
     
      Map output =  func.exec( tf.newTuple(bg) );
     
      Assert.assertTrue(output.containsKey("A") );
      Assert.assertTrue(output.containsKey("B") );
      Assert.assertTrue(output.containsKey("C") );
      Assert.assertTrue(output.containsKey("D") );
View Full Code Here

            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

            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

        assertTrue(r==null);
        r = func.exec(t3);
        assertTrue(r==null);
       
        String matchRegex = "^(.+)\\b\\s+is a\\s+\\b(.+)$";
        TupleFactory tupleFactory = TupleFactory.getInstance();
        Tuple te1 = tupleFactory.newTuple(2);
        te1.set(0,"this is a match");
        te1.set(1, matchRegex);
       
        Tuple te2 = tupleFactory.newTuple(2);
        te2.set(0, "no match");
        te2.set(1, matchRegex);
       
        Tuple te3 = tupleFactory.newTuple(2);
        te3.set(0, null);
        te3.set(1, matchRegex);
    
        REGEX_EXTRACT_ALL funce = new REGEX_EXTRACT_ALL();
        Tuple re = funce.exec(te1);
View Full Code Here

  assertEquals("", m.get("k2"), 2.0);
  assertEquals("", m.get("k3"), "foo");

       
        TOP top = new TOP();
        TupleFactory tupleFactory = TupleFactory.getInstance();
        BagFactory bagFactory = DefaultBagFactory.getInstance();
        Tuple inputTuple = tupleFactory.newTuple(3);
        DataBag dBag = bagFactory.newDefaultBag();
       
        // set N = 10 i.e retain top 10 tuples
        inputTuple.set(0, 10);
        // compare tuples by field number 1
        inputTuple.set(1, 1);
        // set the data bag containing the tuples
        inputTuple.set(2, dBag);

        // generate tuples of the form (group-1, 1), (group-2, 2) ...
        for (long i = 0; i < 100; i++) {
            Tuple nestedTuple = tupleFactory.newTuple(2);
            nestedTuple.set(0, "group-" + i);
            nestedTuple.set(1, i);
            dBag.add(nestedTuple);
        }
       
        DataBag outBag = top.exec(inputTuple);
        assertEquals(outBag.size(), 10L);
        checkItemsGT(outBag, 1, 89);
       
        // two initial results
        Tuple init1 = (new TOP.Initial()).exec(inputTuple);
        Tuple init2 = (new TOP.Initial()).exec(inputTuple);
        // two intermediate results

        DataBag intermedBag = bagFactory.newDefaultBag();
        intermedBag.add(init1);
        intermedBag.add(init2);
        Tuple intermedInput = tupleFactory.newTuple(intermedBag);
        Tuple intermedOutput1 = (new TOP.Intermed()).exec(intermedInput);
        Tuple intermedOutput2 = (new TOP.Intermed()).exec(intermedInput);
        checkItemsGT((DataBag)intermedOutput1.get(2), 1, 94);

        // final result
        DataBag finalInputBag = bagFactory.newDefaultBag();
        finalInputBag.add(intermedOutput1);
        finalInputBag.add(intermedOutput2);
        Tuple finalInput = tupleFactory.newTuple(finalInputBag);
        outBag = (new TOP.Final()).exec(finalInput);
        assertEquals(outBag.size(), 10L);
        checkItemsGT(outBag, 1, 96);
    }
View Full Code Here

        assertEquals("amy smith", t.get(3));
    }
   
    @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

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.