Package org.apache.pig.data

Examples of org.apache.pig.data.DefaultDataBag$DefaultDataBagIterator


    assertEquals(1.11111, ans.getAtomField(2).numval(),0.0005);
  }
 
  public void testCOR() throws Exception{
    EvalFunc<DataBag> COR = new COR("a","b");
    DataBag dBag = new DefaultDataBag();
    Tuple tup1 = new Tuple(1);
    tup1.setField(0, 1);
    dBag.add(tup1);
    tup1 = new Tuple(1);
    tup1.setField(0, 4);
    dBag.add(tup1);
    tup1 = new Tuple(1);
    tup1.setField(0, 8);
    dBag.add(tup1);
    tup1 = new Tuple(1);
    tup1.setField(0, 4);
    dBag.add(tup1);
    tup1 = new Tuple(1);
    tup1.setField(0, 7);
    dBag.add(tup1);
    tup1 = new Tuple(1);
    tup1.setField(0, 8);
    dBag.add(tup1);
    DataBag dBag1 = new DefaultDataBag();
    tup1 = new Tuple(1);
    tup1.setField(0, 2);
    dBag1.add(tup1);
    tup1 = new Tuple(1);
    tup1.setField(0, 2);
    dBag1.add(tup1);
    tup1 = new Tuple(1);
    tup1.setField(0, 3);
    dBag1.add(tup1);
    tup1 = new Tuple(1);
    tup1.setField(0, 3);
    dBag1.add(tup1);
    tup1 = new Tuple(1);
    tup1.setField(0, 2);
    dBag1.add(tup1);
    tup1 = new Tuple(1);
    tup1.setField(0, 4);
    dBag1.add(tup1);
    Tuple input = new Tuple(2);
    input.setField(0, dBag);
    input.setField(1, dBag1);
    DataBag output = new DefaultDataBag();
    COR.exec(input, output);
    Iterator<Tuple> it = output.iterator();
    Tuple ans = (Tuple) it.next();
    assertEquals(ans.getAtomField(0).toString(),"a");
    assertEquals(ans.getAtomField(1).toString(),"b");
    assertEquals(0.582222509739582, ans.getAtomField(2).numval(),0.0005);
  }
View Full Code Here


  public static DataBag[] testDataBagEvals(EvalFunc<DataBag> eval, Tuple[] tuples) {
   
    List<DataBag> res = new ArrayList<DataBag>();
    try {
      for (Tuple t : tuples) {
        DataBag bag = new DefaultDataBag();
        eval.exec(t, bag);
        System.out.println("Converted: " + t + " to (" + bag + ")");
        res.add(bag);
      }
    } catch (IOException e) {
View Full Code Here

    };
   
    ExtractHour eval2 = new ExtractHour();
    testDataAtomEvals(eval2, getTuples(timestamps));

    DataBag bag = new DefaultDataBag();
   
    Tuple t1 = new Tuple();
    t1.appendField(new DataAtom("word"));
    t1.appendField(new DataAtom("02"));
    t1.appendField(new DataAtom(2));
    bag.add(t1);
   
    Tuple t2 = new Tuple();
    t2.appendField(new DataAtom("word"));
    t2.appendField(new DataAtom("05"));
    t2.appendField(new DataAtom(2));
    bag.add(t2);

    Tuple t3 = new Tuple();
    t3.appendField(new DataAtom("word"));
    t3.appendField(new DataAtom("04"));
    t3.appendField(new DataAtom(3));
    bag.add(t3);

    Tuple t4 = new Tuple();
    t4.appendField(new DataAtom("word"));
    t4.appendField(new DataAtom("06"));
    t4.appendField(new DataAtom(4));
    bag.add(t4);

    Tuple[] t = new Tuple[1];
    t[0] = new Tuple();
    t[0].appendField(bag);
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);
View Full Code Here

    }

    @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(
View Full Code Here

    }

    @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(
View Full Code Here

    }

    @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";
View Full Code Here

      return null;
    }

    HCatFieldSchema elementSubFieldSchema = hfs.getArrayElementSchema().getFields().get(0);
    if (elementSubFieldSchema.getType() == Type.STRUCT){
      DataBag db = new DefaultDataBag();
      for (Object o : list){
        db.add(transformToTuple((List<Object>)o,elementSubFieldSchema));
      }
      return db;
    } else {
      return  new HCatArrayBag(list);
    }
View Full Code Here

    return 0;
  }

  @Override
  public void readFields(DataInput arg0) throws IOException {
    convertedBag = new DefaultDataBag();
    convertedBag.readFields(arg0);
  }
View Full Code Here

   * Create a PIG Bag object.
   *
   * @return A Pig DataBag object.
   */
  public static DataBag createBag() {
    return new DefaultDataBag();
  }
View Full Code Here

TOP

Related Classes of org.apache.pig.data.DefaultDataBag$DefaultDataBagIterator

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.