Package com.twitter.elephantbird.pig.util

Examples of com.twitter.elephantbird.pig.util.ProtobufTuple


      return null;
    }
    try {
      DataByteArray bytes = (DataByteArray) input.get(0);
      M value_ = protoConverter_.fromBytes(bytes.get());
      return new ProtobufTuple(value_);
    } catch (IOException e) {
      return null;
    }
  }
View Full Code Here


  }

  @Test
  public void testLazyProtoToPig() throws ExecException {
    Person personProto = Fixtures.buildPersonProto();
    Tuple protoTuple = new ProtobufTuple(personProto);
    Tuple normalTuple = Fixtures.buildPersonTuple();
    List<FieldDescriptor> fieldDescs = personProto.getDescriptorForType().getFields();

    TypeRef<Person> typeRef = PigUtil.getProtobufTypeRef(Person.class.getName());
    Tuple projectedTuple =
      new ProjectedProtobufTupleFactory<Person>(typeRef, evenFields(fieldDescs)).newTuple(personProto);

    int idx = 0;
    for (FieldDescriptor fd : fieldDescs) {
      // Skipping data bags. Data bags actually work; it' just our fixture is not good for this,
      // since it tests "default value" functionality by leaving some elements as null, expecting
      // protobuf conversion to fill the nulls in. Which is what happens. But that means converting back
      // gives us non-null fields, which are not equal to the null fields...
      if (normalTuple.get(fd.getIndex()) instanceof DataBag) {
        continue;
      }
      assertEquals(protoTuple.get(fd.getIndex()), normalTuple.get(fd.getIndex()));
      if (idx%2 == 0) {
        assertEquals(projectedTuple.get(fd.getIndex()/2), normalTuple.get(fd.getIndex()));
      }
      idx++;
    }
View Full Code Here

    ProtobufToPig protoConv = new ProtobufToPig();
    for (int i = 0; i < iterations; i++) {
      Person proto = Fixtures.buildPersonProto();
      Tuple t = protoConv.toTuple(proto);
      t.get(0);
      t = new ProtobufTuple(proto);
      t.get(0);
    }
    StopWatch timer = new StopWatch();
    timer.start();
    for (int i = 0; i < iterations; i++) {
      Person proto = Fixtures.buildPersonProto();
      Tuple t = protoConv.toTuple(proto);
      t.get(0);
    }
    timer.split();
    System.err.println(timer.getSplitTime());
    timer.reset();
    timer.start();
    for (int i = 0; i < iterations; i++) {
      Person proto = Fixtures.buildPersonProto();
      Tuple t = new ProtobufTuple(proto);
      t.get(0);
    }
    timer.split();
    System.err.println(timer.getSplitTime());
   
  }
View Full Code Here

TOP

Related Classes of com.twitter.elephantbird.pig.util.ProtobufTuple

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.