ProtobufDeserializer implements Deserializer { @Override public ObjectInspector getObjectInspector() throws SerDeException { return objectInspector; }  @Override void initialize(Configuration job, Properties tbl); @Override Object deserialize(Writable blob); @Override ObjectInspector getObjectInspector(); @Override SerDeStats getSerDeStats();  }
@Test public final void testObjectInspector() throws SerDeException { ObjectInspector oi = deserializer.getObjectInspector(); assertEquals(oi.getCategory(), Category.STRUCT); ProtobufStructObjectInspector protobufOI = (ProtobufStructObjectInspector) oi; List<Object> readData = protobufOI.getStructFieldsDataAsList(test_ab); assertEquals(readData.size(), 2); @SuppressWarnings("unchecked") ByteString byteStr = (ByteString)readData.get(1); assertEquals(byteStr, ByteString.copyFrom(new byte[] {16,32,64,(byte) 128})); List<Person> persons = (List<Person>) readData.get(0); assertEquals(persons.size(), 3); assertEquals(persons.get(0).getPhoneCount(), 3); assertEquals(persons.get(0).getPhone(2).getType(), PhoneType.HOME); assertEquals(persons.get(0).getId(), 1); assertEquals(persons.get(1).getPhoneCount(), 1); assertEquals(persons.get(1).getPhone(0), test_pn); assertEquals(persons.get(1).getPhone(0).getType(), PhoneType.MOBILE); assertEquals(persons.get(2).getPhoneCount(), 0); assertEquals(persons.get(2).getId(), 3); assertEquals(persons.get(2).getEmail(), ""); }
@Test public final void testObjectInspectorGetTypeName() throws SerDeException { ProtobufStructObjectInspector protobufOI = (ProtobufStructObjectInspector) deserializer .getObjectInspector(); assertEquals(protobufOI.getTypeName(), "struct<person:array<" + "struct<name:string,id:int,email:string," + "phone:array<struct<number:string,type:string>>>>,byteData:binary>"); }
@Test public final void testElementObjectInspector() throws SerDeException { ProtobufStructObjectInspector protobufOI = (ProtobufStructObjectInspector) deserializer .getObjectInspector(); ProtobufStructObjectInspector personOI = new ProtobufStructObjectInspector( Person.getDescriptor()); assertEquals(protobufOI.getStructFieldRef("person").getFieldObjectInspector().getClass(), ObjectInspectorFactory.getStandardListObjectInspector(personOI).getClass()); StandardListObjectInspector phoneOI = (StandardListObjectInspector) personOI.getStructFieldRef( "phone").getFieldObjectInspector(); assertEquals(phoneOI.getListElementObjectInspector().getTypeName(), "struct<number:string,type:string>"); }