Search in sources :

Example 16 with TField

use of org.apache.thrift.protocol.TField 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 17 with TField

use of org.apache.thrift.protocol.TField in project parquet-format by apache.

the class EventBasedThriftReader method readStructContent.

/**
 * reads the content of a struct (fields) from the underlying protocol and passes the events to c
 * @param c the field consumer
 * @throws TException
 */
public void readStructContent(FieldConsumer c) throws TException {
    TField field;
    while (true) {
        field = protocol.readFieldBegin();
        if (field.type == TType.STOP) {
            break;
        }
        c.consumeField(protocol, this, field.id, field.type);
    }
}
Also used : TField(org.apache.thrift.protocol.TField)

Aggregations

TField (org.apache.thrift.protocol.TField)17 TStruct (org.apache.thrift.protocol.TStruct)6 Test (org.junit.Test)5 Properties (java.util.Properties)3 Configuration (org.apache.hadoop.conf.Configuration)3 TCTLSeparatedProtocol (org.apache.hadoop.hive.serde2.thrift.TCTLSeparatedProtocol)3 TConfiguration (org.apache.thrift.TConfiguration)3 TList (org.apache.thrift.protocol.TList)3 TMap (org.apache.thrift.protocol.TMap)3 TMemoryBuffer (org.apache.thrift.transport.TMemoryBuffer)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 HashMap (java.util.HashMap)2 PField (net.morimekta.providence.descriptor.PField)2 JsonElement (com.google.gson.JsonElement)1 InterceptorScopeInvocation (com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)1 ThriftClientCallContext (com.navercorp.pinpoint.plugin.thrift.ThriftClientCallContext)1 ServerMarkerFlagFieldAccessor (com.navercorp.pinpoint.plugin.thrift.field.accessor.ServerMarkerFlagFieldAccessor)1 ArrayList (java.util.ArrayList)1 EnumMap (java.util.EnumMap)1