Package org.apache.pig.data

Examples of org.apache.pig.data.TupleFactory


                + " <START:entity> Smith Consulting <END> .", merged);
    }

    @Test
    public void testAggregateBagOfText() throws IOException {
        TupleFactory tf = TupleFactory.getInstance();
        DefaultDataBag textBag = new DefaultDataBag();

        textBag.add(tf.newTupleNoCopy(Arrays.asList(JOHN_SENTENCE)));
        textBag.add(tf.newTupleNoCopy(Arrays.asList(JOHN_SENTENCE)));
        textBag.add(tf.newTupleNoCopy(Arrays.asList(JOHN_SENTENCE)));
        textBag.add(tf.newTupleNoCopy(Arrays.asList(JOHN_SENTENCE)));
        textBag.add(tf.newTupleNoCopy(Arrays.asList(JOHN_SENTENCE)));
        textBag.add(tf.newTupleNoCopy(Arrays.asList(JOHN_SENTENCE)));

        // all bags
        Tuple input = tf.newTupleNoCopy(Arrays.asList(textBag));
        String merged = aggregator.exec(input);
        String expected = StringUtils.join(
                Arrays.asList(JOHN_SENTENCE, JOHN_SENTENCE), " ");
        expected = "\"" + expected + "\"";
        assertEquals(expected, merged);
View Full Code Here


        assertEquals(expected, merged);
    }

    @Test
    public void testAggregateBagOfTextWithTabs() throws IOException {
        TupleFactory tf = TupleFactory.getInstance();
        DefaultDataBag textBag = new DefaultDataBag();

        textBag.add(tf.newTupleNoCopy(Arrays.asList(JOHN_SENTENCE_WITH_TABS)));
        textBag.add(tf.newTupleNoCopy(Arrays.asList(JOHN_SENTENCE_WITH_TABS)));
        textBag.add(tf.newTupleNoCopy(Arrays.asList(JOHN_SENTENCE_WITH_TABS)));
        textBag.add(tf.newTupleNoCopy(Arrays.asList(JOHN_SENTENCE_WITH_TABS)));
        textBag.add(tf.newTupleNoCopy(Arrays.asList(JOHN_SENTENCE_WITH_TABS)));
        textBag.add(tf.newTupleNoCopy(Arrays.asList(JOHN_SENTENCE_WITH_TABS)));

        // all bags
        Tuple input = tf.newTupleNoCopy(Arrays.asList(textBag));
        String merged = aggregator.exec(input);
        String expected = StringUtils.join(
                Arrays.asList(JOHN_SENTENCE, JOHN_SENTENCE), " ");
        expected = "\"" + expected + "\"";
        assertEquals(expected, merged);
View Full Code Here

        assertEquals(expected, merged);
    }

    @Test
    public void testConcatTextBag() throws IOException {
        TupleFactory tf = TupleFactory.getInstance();
        DefaultDataBag textBag = new DefaultDataBag();

        textBag.add(tf.newTupleNoCopy(Arrays.asList(" foo1")));
        textBag.add(tf.newTupleNoCopy(Arrays.asList("foo2")));
        textBag.add(tf.newTupleNoCopy(Arrays.asList(" foo3 ")));
        textBag.add(tf.newTupleNoCopy(Arrays.asList("foo1")));
        textBag.add(tf.newTupleNoCopy(Arrays.asList("foo4 ")));

        // all bags
        Tuple input = tf.newTupleNoCopy(Arrays.asList(textBag));
        String merged = concatTextBag.exec(input);
        String expected = "foo1 _ foo2 _ foo3 _ foo4";
        assertEquals(expected, merged);
    }
View Full Code Here

    }

    @Test
    public void testNoLoopInPath() throws IOException {
        NoLoopInPath noloopInPathFunc = new NoLoopInPath(" ");
        TupleFactory tf = TupleFactory.getInstance();

        assertTrue(noloopInPathFunc.exec(null));
        assertTrue(noloopInPathFunc.exec(tf.newTupleNoCopy(Collections.emptyList())));
        assertTrue(noloopInPathFunc.exec(tf.newTupleNoCopy(Arrays.asList(""))));
        assertTrue(noloopInPathFunc.exec(tf.newTupleNoCopy(Arrays.asList("a"))));
        assertTrue(noloopInPathFunc.exec(tf.newTupleNoCopy(Arrays.asList("a b c d"))));

        assertFalse(noloopInPathFunc.exec(tf.newTupleNoCopy(Arrays.asList("a a"))));
        assertFalse(noloopInPathFunc.exec(tf.newTupleNoCopy(Arrays.asList("a b c a"))));
        assertFalse(noloopInPathFunc.exec(tf.newTupleNoCopy(Arrays.asList("a b c b"))));
        assertFalse(noloopInPathFunc.exec(tf.newTupleNoCopy(Arrays.asList("a b c c"))));

        // for efficiency reason, this function only check for loops introduced
        // by the last element:
        assertTrue(noloopInPathFunc.exec(tf.newTupleNoCopy(Arrays.asList("a b b d"))));
    }
View Full Code Here

    }

    @Test
    public void testCheckAbstract() throws IOException {
        CheckAbstract abstractChecker = new CheckAbstract();
        TupleFactory tf = TupleFactory.getInstance();
        assertFalse(abstractChecker.exec(null));
        assertFalse(abstractChecker.exec(tf.newTupleNoCopy(Collections.emptyList())));
        assertFalse(abstractChecker.exec(tf.newTupleNoCopy(Arrays.asList((String) null))));
        assertFalse(abstractChecker.exec(tf.newTupleNoCopy(Arrays.asList(""))));
        assertFalse(abstractChecker.exec(tf.newTupleNoCopy(Arrays.asList("Some short boring abstract."))));
        String longBoringAbstract = "Elections by country gives information on elections."
                + " For each de jure and de facto sovereign state and dependent territory"
                + " an article on elections in that entity has been included and "
                + "information on the way the head of state and the parliament or "
                + "legislature is elected. The articles include the results of the "
                + "elections. For a chronological order, see the electoral calendar."
                + " Contents Top · 0–9 · A B C D E F G H I J K L M N O P Q R S T U V W X Y Z";
        assertFalse(abstractChecker.exec(tf.newTupleNoCopy(Arrays.asList(longBoringAbstract))));
        String interestingAbstract = "Mathematics is the study of quantity, structure,"
                + " space, and change. Mathematicians seek out patterns,"
                + " formulate new conjectures, and establish truth by rigorous"
                + " deduction from appropriately chosen axioms and definitions."
                + " There is debate over whether mathematical objects such as"
                + " numbers and points exist naturally or are human creations."
                + " The mathematician Benjamin Peirce called mathematics \"the"
                + " science that draws necessary conclusions\". Albert Einstein,"
                + " on the other hand, stated that \"as far as the laws of"
                + " mathematics refer to reality, they are not certain; and as"
                + " far as they are certain, they do not refer to reality. \""
                + " Through the use of abstraction and logical reasoning,"
                + " mathematics evolved from counting, calculation, measurement,"
                + " and the systematic study of the shapes and motions of"
                + " physical objects.";
        assertTrue(abstractChecker.exec(tf.newTupleNoCopy(Arrays.asList(interestingAbstract))));
    }
View Full Code Here

        String num = s.substring( 0, s.length() - 1 );
        return Long.parseLong( num );
    }

    static Tuple buildTuple(List<Object> objList) {
        TupleFactory tf = TupleFactory.getInstance();
        return tf.newTuple( objList );
    }
View Full Code Here

   
    // Plan to test when result type is ByteArray and casting is requested
    // for example casting of values coming out of map lookup.
    POCast opWithInputTypeAsBA = new POCast(new OperatorKey("", r.nextLong()), -1);
    PhysicalPlan planToTestBACasts = constructPlan(opWithInputTypeAsBA);
    TupleFactory tf = TupleFactory.getInstance();
    {
      Tuple t = tf.newTuple();
      t.append(GenRandomData.genRandMap(r, 10));
      plan.attachInput(t);
      Map map = (Map) t.get(0);
      Result res = op.getNext(map);
      //System.out.println(res.result + " : " + t);
      assertEquals(map, res.result);
        
      planToTestBACasts.attachInput(t);
      res = opWithInputTypeAsBA.getNext(map);
      assertEquals(map, res.result);
    }
   
    {
      Tuple t = tf.newTuple();
      t.append(GenRandomData.genRandMap(r, 10));
      plan.attachInput(t);
      Result res = op.getNext(t);
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
     
    }
   
    {
      Tuple t = tf.newTuple();
      t.append(GenRandomData.genRandMap(r, 10));
      plan.attachInput(t);
      DataBag b = null;
      Result res = op.getNext(b);
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
     
    }
   
    {
      Tuple t = tf.newTuple();
      t.append(GenRandomData.genRandMap(r, 10));
      Integer i = null;
      Result res = op.getNext(i);
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
    }
   
    {    
      Tuple t = tf.newTuple();
      t.append(GenRandomData.genRandMap(r, 10));
      Long i = null;
      Result res = op.getNext(i);
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
    }
   
    {
      Tuple t = tf.newTuple();
      t.append(GenRandomData.genRandMap(r, 10));
      Float i = null;
      Result res = op.getNext(i);
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
    }
   
    {
      Tuple t = tf.newTuple();
      t.append(GenRandomData.genRandMap(r, 10));
      Double i = null;
      Result res = op.getNext(i);
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
    }
   
    {
      Tuple t = tf.newTuple();
      t.append(GenRandomData.genRandMap(r, 10));
      String i = null;
      Result res = op.getNext(i);
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
    }
   
    {
      Tuple t = tf.newTuple();
      t.append(GenRandomData.genRandMap(r, 10));
      plan.attachInput(t);
      DataByteArray i = null;
      Result res = op.getNext(i);
      assertEquals(POStatus.STATUS_ERR, res.returnStatus);
View Full Code Here

     
    }
   
    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

    }
   
    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

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.