use of org.apache.thrift.protocol.TMap in project hive by apache.
the class DynamicSerDeTypeMap method deserialize.
@Override
public Map<Object, Object> deserialize(Object reuse, TProtocol iprot) throws SerDeException, TException, IllegalAccessException {
HashMap<Object, Object> deserializeReuse;
if (reuse != null) {
deserializeReuse = (HashMap<Object, Object>) reuse;
deserializeReuse.clear();
} else {
deserializeReuse = new HashMap<Object, Object>();
}
TMap themap = iprot.readMapBegin();
if (themap == null) {
return null;
}
// themap might be reused by the Protocol.
int mapSize = themap.size;
for (int i = 0; i < mapSize; i++) {
Object key = getKeyType().deserialize(null, iprot);
Object value = getValueType().deserialize(null, iprot);
deserializeReuse.put(key, value);
}
// in theory, the below call isn't needed in non thrift_mode, but let's not
// get too crazy
iprot.readMapEnd();
return deserializeReuse;
}
use of org.apache.thrift.protocol.TMap in project commons by twitter.
the class TTextProtocol method readMapBegin.
@Override
public TMap readMapBegin() throws TException {
getCurrentContext().read();
JsonElement curElem = getCurrentContext().getCurrentChild();
if (getCurrentContext().isMapKey()) {
curElem = new JsonStreamParser(curElem.getAsString()).next();
}
if (!curElem.isJsonObject()) {
throw new TException("Expected JSON Object!");
}
pushContext(new MapContext(curElem.getAsJsonObject()));
return new TMap(UNUSED_TYPE, UNUSED_TYPE, curElem.getAsJsonObject().entrySet().size());
}
use of org.apache.thrift.protocol.TMap in project parquet-mr by apache.
the class BufferedProtocolReadToWrite method readOneMap.
private boolean readOneMap(TProtocol in, List<Action> buffer, MapType mapType) throws TException {
final TMap map = in.readMapBegin();
buffer.add(new Action() {
@Override
public void write(TProtocol out) throws TException {
out.writeMapBegin(map);
}
@Override
public String toDebugString() {
return "<k=" + map.keyType + ", v=" + map.valueType + ", s=" + map.size + ">[";
}
});
boolean hasFieldIgnored = false;
for (int i = 0; i < map.size; i++) {
hasFieldIgnored |= readOneValue(in, map.keyType, buffer, mapType.getKey().getType());
hasFieldIgnored |= readOneValue(in, map.valueType, buffer, mapType.getValue().getType());
}
in.readMapEnd();
buffer.add(MAP_END);
return hasFieldIgnored;
}
use of org.apache.thrift.protocol.TMap in project skywalking-java by apache.
the class ServerInProtocolWrapper method readFieldBegin.
@Override
public TField readFieldBegin() throws TException {
final TField field = super.readFieldBegin();
if (field.id == SW_MAGIC_FIELD_ID && field.type == TType.MAP) {
try {
TMap tMap = super.readMapBegin();
Map<String, String> header = new HashMap<>(tMap.size);
for (int i = 0; i < tMap.size; i++) {
header.put(readString(), readString());
}
AbstractSpan span = ContextManager.createEntrySpan(context.getOperatorName(), createContextCarrier(header));
span.start(context.startTime);
span.tag(TAG_ARGS, context.getArguments());
span.setComponent(ComponentsDefine.THRIFT_SERVER);
SpanLayer.asRPCFramework(span);
ContextManager.getRuntimeContext().put(HAVE_CREATED_SPAN, true);
} catch (Throwable throwable) {
LOGGER.error("Failed to resolve header or create EntrySpan.", throwable);
} finally {
context = null;
super.readMapEnd();
super.readFieldEnd();
}
return readFieldBegin();
}
return field;
}
Aggregations