Search in sources :

Example 6 with TList

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

the class MockMessage method write.

public void write(TProtocol oprot) throws TException {
    validate();
    oprot.writeStructBegin(STRUCT_DESC);
    if (this.name != null) {
        oprot.writeFieldBegin(NAME_FIELD_DESC);
        oprot.writeString(this.name);
        oprot.writeFieldEnd();
    }
    if (this.mappings != null) {
        oprot.writeFieldBegin(MAPPINGS_FIELD_DESC);
        {
            oprot.writeMapBegin(new TMap(TType.I64, TType.MAP, this.mappings.size()));
            for (Map.Entry<Long, Map<String, Integer>> _iter14 : this.mappings.entrySet()) {
                oprot.writeI64(_iter14.getKey());
                {
                    oprot.writeMapBegin(new TMap(TType.STRING, TType.I32, _iter14.getValue().size()));
                    for (Map.Entry<String, Integer> _iter15 : _iter14.getValue().entrySet()) {
                        oprot.writeString(_iter15.getKey());
                        oprot.writeI32(_iter15.getValue());
                    }
                    oprot.writeMapEnd();
                }
            }
            oprot.writeMapEnd();
        }
        oprot.writeFieldEnd();
    }
    if (this.intList != null) {
        oprot.writeFieldBegin(INT_LIST_FIELD_DESC);
        {
            oprot.writeListBegin(new TList(TType.I16, this.intList.size()));
            for (short _iter16 : this.intList) {
                oprot.writeI16(_iter16);
            }
            oprot.writeListEnd();
        }
        oprot.writeFieldEnd();
    }
    if (this.strSet != null) {
        oprot.writeFieldBegin(STR_SET_FIELD_DESC);
        {
            oprot.writeSetBegin(new TSet(TType.STRING, this.strSet.size()));
            for (String _iter17 : this.strSet) {
                oprot.writeString(_iter17);
            }
            oprot.writeSetEnd();
        }
        oprot.writeFieldEnd();
    }
    oprot.writeFieldStop();
    oprot.writeStructEnd();
}
Also used : TList(org.apache.thrift.protocol.TList) TSet(org.apache.thrift.protocol.TSet) HashMap(java.util.HashMap) Map(java.util.Map) EnumMap(java.util.EnumMap) TMap(org.apache.thrift.protocol.TMap) TMap(org.apache.thrift.protocol.TMap)

Example 7 with TList

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

the class TestTCTLSeparatedProtocol method testQuotedWrites.

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();
    // shouldl return nulls at end
    prot.readFieldBegin();
    assertNull(prot.readString());
    prot.readFieldEnd();
    // shouldl 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) 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)

Example 8 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 9 with TList

use of org.apache.thrift.protocol.TList in project pinpoint by naver.

the class TReplaceListProtocol method writeListBegin.

@Override
public void writeListBegin(TList list) throws TException {
    if (!writeFieldBegin) {
        protocol.writeListBegin(list);
        return;
    }
    if (writeListDepth == 0 && currentField != null) {
        List<ByteArrayOutput> outputs = replaceFields.get(currentField.name);
        if (outputs == null) {
            throw new TException("not found replace field - " + currentField.name);
        }
        final TList replaceList = new TList(list.elemType, outputs.size());
        protocol.writeListBegin(replaceList);
        for (ByteArrayOutput output : outputs) {
            try {
                final OutputStream out = ((ByteArrayOutputStreamTransport) getTransport()).getByteArrayOutputStream();
                output.writeTo(out);
            } catch (IOException e) {
                throw new TException(e);
            }
        }
    }
    writeListDepth++;
}
Also used : TException(org.apache.thrift.TException) TList(org.apache.thrift.protocol.TList) OutputStream(java.io.OutputStream) IOException(java.io.IOException)

Aggregations

TList (org.apache.thrift.protocol.TList)9 TField (org.apache.thrift.protocol.TField)3 TMap (org.apache.thrift.protocol.TMap)3 ArrayList (java.util.ArrayList)2 EnumMap (java.util.EnumMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Properties (java.util.Properties)2 Configuration (org.apache.hadoop.conf.Configuration)2 TCTLSeparatedProtocol (org.apache.hadoop.hive.serde2.thrift.TCTLSeparatedProtocol)2 TSet (org.apache.thrift.protocol.TSet)2 TStruct (org.apache.thrift.protocol.TStruct)2 TMemoryBuffer (org.apache.thrift.transport.TMemoryBuffer)2 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 HashSet (java.util.HashSet)1 List (java.util.List)1 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)1 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)1 WriteNullsProtocol (org.apache.hadoop.hive.serde2.thrift.WriteNullsProtocol)1