use of org.apache.thrift.protocol.TSet in project hive by apache.
the class DynamicSerDeTypeSet method serialize.
@Override
public void serialize(Object o, ObjectInspector oi, TProtocol oprot) throws TException, SerDeException, NoSuchFieldException, IllegalAccessException {
ListObjectInspector loi = (ListObjectInspector) oi;
Set<Object> set = (Set<Object>) o;
DynamicSerDeTypeBase mt = getElementType();
tset = new TSet(mt.getType(), set.size());
oprot.writeSetBegin(tset);
for (Object element : set) {
mt.serialize(element, loi.getListElementObjectInspector(), oprot);
}
// in theory, the below call isn't needed in non thrift_mode, but let's not
// get too crazy
oprot.writeSetEnd();
}
use of org.apache.thrift.protocol.TSet in project hive by apache.
the class DynamicSerDeTypeSet method deserialize.
/**
* NOTE: Set is not supported by Hive yet.
*/
@Override
public Object deserialize(Object reuse, TProtocol iprot) throws SerDeException, TException, IllegalAccessException {
TSet theset = iprot.readSetBegin();
if (theset == null) {
return null;
}
Set<Object> result;
if (reuse != null) {
result = (Set<Object>) reuse;
result.clear();
} else {
result = new HashSet<Object>();
}
for (int i = 0; i < theset.size; i++) {
Object elem = getElementType().deserialize(null, iprot);
result.add(elem);
}
// in theory, the below call isn't needed in non thrift_mode, but let's not
// get too crazy
iprot.readSetEnd();
return result;
}
use of org.apache.thrift.protocol.TSet in project providence by morimekta.
the class TProtocolSerializer method readTypedValue.
private Object readTypedValue(byte tType, PDescriptor type, TProtocol protocol, boolean allowNull) throws TException, SerializerException {
if (tType != forType(type.getType())) {
throw new SerializerException("Expected type " + asString(forType(type.getType())) + " but found " + asString(tType));
}
switch(tType) {
case BinaryType.BOOL:
return protocol.readBool();
case BinaryType.BYTE:
return protocol.readByte();
case BinaryType.I16:
return protocol.readI16();
case BinaryType.I32:
if (PType.ENUM == type.getType()) {
PEnumDescriptor<?> et = (PEnumDescriptor<?>) type;
PEnumBuilder<?> eb = et.builder();
int value = protocol.readI32();
eb.setById(value);
if (!eb.valid() && !allowNull) {
throw new SerializerException("Invalid enum value " + value + " for " + et.getQualifiedName());
}
return eb.build();
} else {
return protocol.readI32();
}
case BinaryType.I64:
return protocol.readI64();
case BinaryType.DOUBLE:
return protocol.readDouble();
case BinaryType.STRING:
if (type == PPrimitive.BINARY) {
ByteBuffer buffer = protocol.readBinary();
return Binary.wrap(buffer.array());
}
return protocol.readString();
case BinaryType.STRUCT:
return readMessage(protocol, (PMessageDescriptor<?, ?>) type);
case BinaryType.LIST:
TList listInfo = protocol.readListBegin();
PList<Object> lDesc = (PList<Object>) type;
PDescriptor liDesc = lDesc.itemDescriptor();
PList.Builder<Object> list = lDesc.builder();
for (int i = 0; i < listInfo.size; ++i) {
list.add(readTypedValue(listInfo.elemType, liDesc, protocol, false));
}
protocol.readListEnd();
return list.build();
case BinaryType.SET:
TSet setInfo = protocol.readSetBegin();
PSet<Object> sDesc = (PSet<Object>) type;
PDescriptor siDesc = sDesc.itemDescriptor();
PSet.Builder<Object> set = sDesc.builder();
for (int i = 0; i < setInfo.size; ++i) {
set.add(readTypedValue(setInfo.elemType, siDesc, protocol, false));
}
protocol.readSetEnd();
return set.build();
case BinaryType.MAP:
TMap mapInfo = protocol.readMapBegin();
PMap<Object, Object> mDesc = (PMap<Object, Object>) type;
PDescriptor mkDesc = mDesc.keyDescriptor();
PDescriptor miDesc = mDesc.itemDescriptor();
PMap.Builder<Object, Object> map = mDesc.builder();
for (int i = 0; i < mapInfo.size; ++i) {
Object key = readTypedValue(mapInfo.keyType, mkDesc, protocol, false);
Object val = readTypedValue(mapInfo.valueType, miDesc, protocol, false);
map.put(key, val);
}
protocol.readMapEnd();
return map.build();
default:
throw new SerializerException("Unsupported protocol field type: " + tType);
}
}
use of org.apache.thrift.protocol.TSet in project providence by morimekta.
the class TProtocolSerializer method writeTypedValue.
private void writeTypedValue(Object item, PDescriptor type, TProtocol protocol) throws TException, SerializerException {
switch(type.getType()) {
case BOOL:
protocol.writeBool((Boolean) item);
break;
case BYTE:
protocol.writeByte((Byte) item);
break;
case I16:
protocol.writeI16((Short) item);
break;
case I32:
protocol.writeI32((Integer) item);
break;
case I64:
protocol.writeI64((Long) item);
break;
case DOUBLE:
protocol.writeDouble((Double) item);
break;
case STRING:
protocol.writeString((String) item);
break;
case BINARY:
protocol.writeBinary(((Binary) item).getByteBuffer());
break;
case ENUM:
PEnumValue<?> value = (PEnumValue<?>) item;
protocol.writeI32(value.asInteger());
break;
case MESSAGE:
writeMessage((PMessage<?, ?>) item, protocol);
break;
case LIST:
PList<?> lType = (PList<?>) type;
List<?> list = (List<?>) item;
TList listInfo = new TList(forType(lType.itemDescriptor().getType()), list.size());
protocol.writeListBegin(listInfo);
for (Object i : list) {
writeTypedValue(i, lType.itemDescriptor(), protocol);
}
protocol.writeListEnd();
break;
case SET:
PSet<?> sType = (PSet<?>) type;
Set<?> set = (Set<?>) item;
TSet setInfo = new TSet(forType(sType.itemDescriptor().getType()), set.size());
protocol.writeSetBegin(setInfo);
for (Object i : set) {
writeTypedValue(i, sType.itemDescriptor(), protocol);
}
protocol.writeSetEnd();
break;
case MAP:
PMap<?, ?> mType = (PMap<?, ?>) type;
Map<?, ?> map = (Map<?, ?>) item;
protocol.writeMapBegin(new TMap(forType(mType.keyDescriptor().getType()), forType(mType.itemDescriptor().getType()), map.size()));
for (Map.Entry<?, ?> entry : map.entrySet()) {
writeTypedValue(entry.getKey(), mType.keyDescriptor(), protocol);
writeTypedValue(entry.getValue(), mType.itemDescriptor(), protocol);
}
protocol.writeMapEnd();
break;
default:
break;
}
}
use of org.apache.thrift.protocol.TSet in project parquet-mr by apache.
the class DefaultEventsVisitor method visit.
@Override
public Void visit(final ThriftType.SetType setType, Void v) {
dummyEvents.add(new ParquetProtocol("readSetBegin()") {
@Override
public TSet readSetBegin() throws TException {
return new TSet();
}
});
dummyEvents.add(new ParquetProtocol("readSetEnd()") {
@Override
public void readSetEnd() throws TException {
}
});
return null;
}
Aggregations