use of org.apache.parquet.pig.PigSchemaConverter in project parquet-mr by apache.
the class TestThriftToPigCompatibility method validateSameTupleAsEB.
/**
* <ul> steps:
* <li>Writes using the thrift mapping
* <li>Reads using the pig mapping
* <li>Use Elephant bird to convert from thrift to pig
* <li>Check that both transformations give the same result
* @param o the object to convert
* @throws TException
*/
public static <T extends TBase<?, ?>> void validateSameTupleAsEB(T o) throws TException {
final ThriftSchemaConverter thriftSchemaConverter = new ThriftSchemaConverter();
@SuppressWarnings("unchecked") final Class<T> class1 = (Class<T>) o.getClass();
final MessageType schema = thriftSchemaConverter.convert(class1);
final StructType structType = ThriftSchemaConverter.toStructType(class1);
final ThriftToPig<T> thriftToPig = new ThriftToPig<T>(class1);
final Schema pigSchema = thriftToPig.toSchema();
final TupleRecordMaterializer tupleRecordConverter = new TupleRecordMaterializer(schema, pigSchema, true);
RecordConsumer recordConsumer = new ConverterConsumer(tupleRecordConverter.getRootConverter(), schema);
final MessageColumnIO columnIO = new ColumnIOFactory().getColumnIO(schema);
ParquetWriteProtocol p = new ParquetWriteProtocol(new RecordConsumerLoggingWrapper(recordConsumer), columnIO, structType);
o.write(p);
final Tuple t = tupleRecordConverter.getCurrentRecord();
final Tuple expected = thriftToPig.getPigTuple(o);
assertEquals(expected.toString(), t.toString());
final MessageType filtered = new PigSchemaConverter().filter(schema, pigSchema);
assertEquals(schema.toString(), filtered.toString());
}
use of org.apache.parquet.pig.PigSchemaConverter in project parquet-mr by apache.
the class TestParquetWriteProtocol method validatePig.
private MessageType validatePig(String[] expectations, TBase<?, ?> a) {
ThriftToPig<TBase<?, ?>> thriftToPig = new ThriftToPig(a.getClass());
ExpectationValidatingRecordConsumer recordConsumer = new ExpectationValidatingRecordConsumer(new ArrayDeque<String>(Arrays.asList(expectations)));
Schema pigSchema = thriftToPig.toSchema();
LOG.info("{}", pigSchema);
MessageType schema = new PigSchemaConverter().convert(pigSchema);
LOG.info("{}", schema);
TupleWriteSupport tupleWriteSupport = new TupleWriteSupport(pigSchema);
tupleWriteSupport.init(null);
tupleWriteSupport.prepareForWrite(recordConsumer);
final Tuple pigTuple = thriftToPig.getPigTuple(a);
LOG.info("{}", pigTuple);
tupleWriteSupport.write(pigTuple);
return schema;
}
Aggregations