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