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();
}
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);
}
}
Aggregations