Search in sources :

Example 1 with ListConsumer

use of org.apache.parquet.format.event.TypedConsumer.ListConsumer 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);
        }
    };
}
Also used : TList(org.apache.thrift.protocol.TList) ListConsumer(org.apache.parquet.format.event.TypedConsumer.ListConsumer) BoolConsumer(org.apache.parquet.format.event.TypedConsumer.BoolConsumer) StructConsumer(org.apache.parquet.format.event.TypedConsumer.StructConsumer) Consumer(org.apache.parquet.format.event.Consumers.Consumer) TProtocol(org.apache.thrift.protocol.TProtocol) ListConsumer(org.apache.parquet.format.event.TypedConsumer.ListConsumer) ArrayList(java.util.ArrayList) TList(org.apache.thrift.protocol.TList) List(java.util.List)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Consumer (org.apache.parquet.format.event.Consumers.Consumer)1 BoolConsumer (org.apache.parquet.format.event.TypedConsumer.BoolConsumer)1 ListConsumer (org.apache.parquet.format.event.TypedConsumer.ListConsumer)1 StructConsumer (org.apache.parquet.format.event.TypedConsumer.StructConsumer)1 TList (org.apache.thrift.protocol.TList)1 TProtocol (org.apache.thrift.protocol.TProtocol)1