Search in sources :

Example 1 with ExpectationValidatingRecordConsumer

use of org.apache.parquet.io.ExpectationValidatingRecordConsumer in project parquet-mr by apache.

the class TestParquetWriteProtocol method validateThrift.

private void validateThrift(String[] expectations, TBase<?, ?> a) throws TException {
    final ThriftSchemaConverter thriftSchemaConverter = new ThriftSchemaConverter();
    // System.out.println(a);
    final Class<TBase<?, ?>> class1 = (Class<TBase<?, ?>>) a.getClass();
    final MessageType schema = thriftSchemaConverter.convert(class1);
    LOG.info("{}", schema);
    final StructType structType = thriftSchemaConverter.toStructType(class1);
    ExpectationValidatingRecordConsumer recordConsumer = new ExpectationValidatingRecordConsumer(new ArrayDeque<String>(Arrays.asList(expectations)));
    final MessageColumnIO columnIO = new ColumnIOFactory().getColumnIO(schema);
    ParquetWriteProtocol p = new ParquetWriteProtocol(new RecordConsumerLoggingWrapper(recordConsumer), columnIO, structType);
    a.write(p);
}
Also used : StructType(org.apache.parquet.thrift.struct.ThriftType.StructType) RecordConsumerLoggingWrapper(org.apache.parquet.io.RecordConsumerLoggingWrapper) ParquetWriteProtocol(org.apache.parquet.thrift.ParquetWriteProtocol) ExpectationValidatingRecordConsumer(org.apache.parquet.io.ExpectationValidatingRecordConsumer) MessageColumnIO(org.apache.parquet.io.MessageColumnIO) ColumnIOFactory(org.apache.parquet.io.ColumnIOFactory) ThriftSchemaConverter(org.apache.parquet.thrift.ThriftSchemaConverter) TBase(org.apache.thrift.TBase) MessageType(org.apache.parquet.schema.MessageType)

Example 2 with ExpectationValidatingRecordConsumer

use of org.apache.parquet.io.ExpectationValidatingRecordConsumer 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;
}
Also used : Schema(org.apache.pig.impl.logicalLayer.schema.Schema) PigSchemaConverter(org.apache.parquet.pig.PigSchemaConverter) TBase(org.apache.thrift.TBase) TupleWriteSupport(org.apache.parquet.pig.TupleWriteSupport) ExpectationValidatingRecordConsumer(org.apache.parquet.io.ExpectationValidatingRecordConsumer) ThriftToPig(com.twitter.elephantbird.pig.util.ThriftToPig) MessageType(org.apache.parquet.schema.MessageType) Tuple(org.apache.pig.data.Tuple)

Aggregations

ExpectationValidatingRecordConsumer (org.apache.parquet.io.ExpectationValidatingRecordConsumer)2 MessageType (org.apache.parquet.schema.MessageType)2 TBase (org.apache.thrift.TBase)2 ThriftToPig (com.twitter.elephantbird.pig.util.ThriftToPig)1 ColumnIOFactory (org.apache.parquet.io.ColumnIOFactory)1 MessageColumnIO (org.apache.parquet.io.MessageColumnIO)1 RecordConsumerLoggingWrapper (org.apache.parquet.io.RecordConsumerLoggingWrapper)1 PigSchemaConverter (org.apache.parquet.pig.PigSchemaConverter)1 TupleWriteSupport (org.apache.parquet.pig.TupleWriteSupport)1 ParquetWriteProtocol (org.apache.parquet.thrift.ParquetWriteProtocol)1 ThriftSchemaConverter (org.apache.parquet.thrift.ThriftSchemaConverter)1 StructType (org.apache.parquet.thrift.struct.ThriftType.StructType)1 Tuple (org.apache.pig.data.Tuple)1 Schema (org.apache.pig.impl.logicalLayer.schema.Schema)1