use of org.apache.parquet.format.event.Consumers.Consumer 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);
}
}
use of org.apache.parquet.format.event.Consumers.Consumer in project parquet-format by apache.
the class TBaseStructConsumer method listOf.
/**
* To consume a list of elements
* @param c the type of the list content
* @param consumer the consumer that will receive the list
* @return a ListConsumer that can be passed to the DelegatingFieldConsumer
*/
public static <T extends TBase<T, ? extends TFieldIdEnum>> ListConsumer listOf(Class<T> c, final Consumer<List<T>> consumer) {
class ListConsumer implements Consumer<T> {
List<T> list;
@Override
public void consume(T t) {
list.add(t);
}
}
final ListConsumer co = new ListConsumer();
return new DelegatingListElementsConsumer(struct(c, co)) {
@Override
public void consumeList(TProtocol protocol, EventBasedThriftReader reader, TList tList) throws TException {
co.list = new ArrayList<T>();
super.consumeList(protocol, reader, tList);
consumer.consume(co.list);
}
};
}
Aggregations