@Test
 public void testToThriftTypeWithoutManualProjection() throws Exception {
   ThriftSchemaConverter schemaConverter = new ThriftSchemaConverter();
   final StructType converted = schemaConverter.toStructType(AddressBook.class);
   final String json = converted.toJSON();
   System.out.println(json);
   final ThriftType fromJSON = StructType.fromJSON(json);
   assertEquals(json, fromJSON.toJSON());
 }
Ejemplo n.º 2
0
 private StructConverter(List<TProtocol> events, GroupType parquetSchema, ThriftField field) {
   this.events = events;
   this.name = field.getName();
   this.tStruct = new TStruct(name);
   this.thriftType = (StructType) field.getType();
   this.schemaSize = parquetSchema.getFieldCount();
   this.converters = new Converter[this.schemaSize];
   List<ThriftField> thriftChildren = thriftType.getChildren();
   for (int i = 0; i < schemaSize; i++) {
     Type schemaType = parquetSchema.getType(i);
     String fieldName = schemaType.getName();
     ThriftField matchingThrift = null;
     for (ThriftField childField : thriftChildren) {
       String thriftChildName = childField.getName();
       if (thriftChildName != null && thriftChildName.equalsIgnoreCase(fieldName)) {
         matchingThrift = childField;
         break;
       }
     }
     if (matchingThrift == null) {
       // this means the file did not contain that field
       // it will never be populated in this instance
       // other files might populate it
       continue;
     }
     if (schemaType.isPrimitive()) {
       converters[i] =
           new PrimitiveFieldHandler(
               newConverter(events, schemaType, matchingThrift).asPrimitiveConverter(),
               matchingThrift,
               events);
     } else {
       converters[i] =
           new GroupFieldhandler(
               newConverter(events, schemaType, matchingThrift).asGroupConverter(),
               matchingThrift,
               events);
     }
   }
 }