Search in sources :

Example 11 with TList

use of org.apache.thrift.protocol.TList in project parquet-mr by apache.

the class ProtocolReadToWrite method readOneList.

private void readOneList(TProtocol in, TProtocol out) throws TException {
    final TList list = in.readListBegin();
    out.writeListBegin(list);
    readCollectionElements(in, out, list.size, list.elemType);
    in.readListEnd();
    out.writeListEnd();
}
Also used : TList(org.apache.thrift.protocol.TList)

Example 12 with TList

use of org.apache.thrift.protocol.TList in project parquet-mr by apache.

the class BufferedProtocolReadToWrite method readOneList.

private boolean readOneList(TProtocol in, List<Action> buffer, ListType expectedType) throws TException {
    final TList list = in.readListBegin();
    buffer.add(new Action() {

        @Override
        public void write(TProtocol out) throws TException {
            out.writeListBegin(list);
        }

        @Override
        public String toDebugString() {
            return "<e=" + list.elemType + ", s=" + list.size + ">{";
        }
    });
    boolean hasFieldsIgnored = readCollectionElements(in, list.size, list.elemType, buffer, expectedType.getValues().getType());
    in.readListEnd();
    buffer.add(LIST_END);
    return hasFieldsIgnored;
}
Also used : TException(org.apache.thrift.TException) TList(org.apache.thrift.protocol.TList) TProtocol(org.apache.thrift.protocol.TProtocol)

Example 13 with TList

use of org.apache.thrift.protocol.TList in project hive by apache.

the class TestTCTLSeparatedProtocol method testQuotedWrites.

@Test
public void testQuotedWrites() throws Exception {
    TMemoryBuffer trans = new TMemoryBuffer(4096);
    TCTLSeparatedProtocol prot = new TCTLSeparatedProtocol(trans, 4096);
    Properties schema = new Properties();
    schema.setProperty(serdeConstants.QUOTE_CHAR, "\"");
    schema.setProperty(serdeConstants.FIELD_DELIM, ",");
    prot.initialize(new Configuration(), schema);
    String testStr = "\"hello, world!\"";
    prot.writeStructBegin(new TStruct());
    prot.writeFieldBegin(new TField());
    prot.writeString(testStr);
    prot.writeFieldEnd();
    prot.writeFieldBegin(new TField());
    prot.writeListBegin(new TList());
    prot.writeString("elem1");
    prot.writeString("elem2");
    prot.writeListEnd();
    prot.writeFieldEnd();
    prot.writeStructEnd();
    prot.writeString("\n");
    trans.flush();
    byte[] b = new byte[4096];
    int len = trans.read(b, 0, b.length);
    trans = new TMemoryBuffer(4096);
    trans.write(b, 0, len);
    prot = new TCTLSeparatedProtocol(trans, 1024);
    prot.initialize(new Configuration(), schema);
    prot.readStructBegin();
    prot.readFieldBegin();
    final String firstRead = prot.readString();
    prot.readFieldEnd();
    testStr = testStr.replace("\"", "");
    assertEquals(testStr, firstRead);
    // the 2 element list
    prot.readFieldBegin();
    TList l = prot.readListBegin();
    assertTrue(l.size == 2);
    assertTrue(prot.readString().equals("elem1"));
    assertTrue(prot.readString().equals("elem2"));
    prot.readListEnd();
    prot.readFieldEnd();
    // should return nulls at end
    prot.readFieldBegin();
    assertNull(prot.readString());
    prot.readFieldEnd();
    // should return nulls at end
    prot.readFieldBegin();
    assertNull(prot.readString());
    prot.readFieldEnd();
    prot.readStructEnd();
}
Also used : TList(org.apache.thrift.protocol.TList) TMemoryBuffer(org.apache.thrift.transport.TMemoryBuffer) TConfiguration(org.apache.thrift.TConfiguration) Configuration(org.apache.hadoop.conf.Configuration) TField(org.apache.thrift.protocol.TField) Properties(java.util.Properties) TStruct(org.apache.thrift.protocol.TStruct) TCTLSeparatedProtocol(org.apache.hadoop.hive.serde2.thrift.TCTLSeparatedProtocol) Test(org.junit.Test)

Example 14 with TList

use of org.apache.thrift.protocol.TList in project hive by apache.

the class TBinarySortableProtocol method readListBegin.

/**
 * This method always return the same instance of TList to avoid creating new
 * instances. It is the responsibility of the caller to read the value before
 * calling this method again.
 */
@Override
public TList readListBegin() throws TException {
    stackLevel++;
    tlist = new TList(ORDERED_TYPE, readI32());
    if (tlist.size == 0 && lastPrimitiveWasNull()) {
        return null;
    }
    return tlist;
}
Also used : TList(org.apache.thrift.protocol.TList)

Example 15 with TList

use of org.apache.thrift.protocol.TList 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

TList (org.apache.thrift.protocol.TList)18 TMap (org.apache.thrift.protocol.TMap)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 TSet (org.apache.thrift.protocol.TSet)4 Map (java.util.Map)3 TException (org.apache.thrift.TException)3 TField (org.apache.thrift.protocol.TField)3 TProtocol (org.apache.thrift.protocol.TProtocol)3 EnumMap (java.util.EnumMap)2 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 PList (net.morimekta.providence.descriptor.PList)2 PMap (net.morimekta.providence.descriptor.PMap)2 PSet (net.morimekta.providence.descriptor.PSet)2 Configuration (org.apache.hadoop.conf.Configuration)2 TCTLSeparatedProtocol (org.apache.hadoop.hive.serde2.thrift.TCTLSeparatedProtocol)2 Consumer (org.apache.parquet.format.event.Consumers.Consumer)2 ListConsumer (org.apache.parquet.format.event.TypedConsumer.ListConsumer)2 StructConsumer (org.apache.parquet.format.event.TypedConsumer.StructConsumer)2