Search in sources :

Example 1 with DelegatingFieldConsumer

use of org.apache.parquet.format.event.Consumers.DelegatingFieldConsumer in project parquet-format by apache.

the class Util method readFileMetaData.

public static void readFileMetaData(InputStream from, final FileMetaDataConsumer consumer, boolean skipRowGroups) throws IOException {
    try {
        DelegatingFieldConsumer eventConsumer = fieldConsumer().onField(VERSION, new I32Consumer() {

            @Override
            public void consume(int value) {
                consumer.setVersion(value);
            }
        }).onField(SCHEMA, listOf(SchemaElement.class, new Consumer<List<SchemaElement>>() {

            @Override
            public void consume(List<SchemaElement> schema) {
                consumer.setSchema(schema);
            }
        })).onField(NUM_ROWS, new I64Consumer() {

            @Override
            public void consume(long value) {
                consumer.setNumRows(value);
            }
        }).onField(KEY_VALUE_METADATA, listElementsOf(struct(KeyValue.class, new Consumer<KeyValue>() {

            @Override
            public void consume(KeyValue kv) {
                consumer.addKeyValueMetaData(kv);
            }
        }))).onField(CREATED_BY, new StringConsumer() {

            @Override
            public void consume(String value) {
                consumer.setCreatedBy(value);
            }
        });
        if (!skipRowGroups) {
            eventConsumer = eventConsumer.onField(ROW_GROUPS, listElementsOf(struct(RowGroup.class, new Consumer<RowGroup>() {

                @Override
                public void consume(RowGroup rowGroup) {
                    consumer.addRowGroup(rowGroup);
                }
            })));
        }
        new EventBasedThriftReader(protocol(from)).readStruct(eventConsumer);
    } catch (TException e) {
        throw new IOException("can not read FileMetaData: " + e.getMessage(), e);
    }
}
Also used : TException(org.apache.thrift.TException) EventBasedThriftReader(org.apache.parquet.format.event.EventBasedThriftReader) I64Consumer(org.apache.parquet.format.event.TypedConsumer.I64Consumer) I32Consumer(org.apache.parquet.format.event.TypedConsumer.I32Consumer) IOException(java.io.IOException) StringConsumer(org.apache.parquet.format.event.TypedConsumer.StringConsumer) Consumers.fieldConsumer(org.apache.parquet.format.event.Consumers.fieldConsumer) StringConsumer(org.apache.parquet.format.event.TypedConsumer.StringConsumer) DelegatingFieldConsumer(org.apache.parquet.format.event.Consumers.DelegatingFieldConsumer) I64Consumer(org.apache.parquet.format.event.TypedConsumer.I64Consumer) I32Consumer(org.apache.parquet.format.event.TypedConsumer.I32Consumer) Consumer(org.apache.parquet.format.event.Consumers.Consumer) DelegatingFieldConsumer(org.apache.parquet.format.event.Consumers.DelegatingFieldConsumer) List(java.util.List)

Aggregations

IOException (java.io.IOException)1 List (java.util.List)1 Consumer (org.apache.parquet.format.event.Consumers.Consumer)1 DelegatingFieldConsumer (org.apache.parquet.format.event.Consumers.DelegatingFieldConsumer)1 Consumers.fieldConsumer (org.apache.parquet.format.event.Consumers.fieldConsumer)1 EventBasedThriftReader (org.apache.parquet.format.event.EventBasedThriftReader)1 I32Consumer (org.apache.parquet.format.event.TypedConsumer.I32Consumer)1 I64Consumer (org.apache.parquet.format.event.TypedConsumer.I64Consumer)1 StringConsumer (org.apache.parquet.format.event.TypedConsumer.StringConsumer)1 TException (org.apache.thrift.TException)1