Search in sources :

Example 16 with TMap

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;
}
Also used : TMap(org.apache.thrift.protocol.TMap)

Example 17 with TMap

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());
}
Also used : TException(org.apache.thrift.TException) JsonElement(com.google.gson.JsonElement) JsonStreamParser(com.google.gson.JsonStreamParser) TMap(org.apache.thrift.protocol.TMap)

Example 18 with TMap

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;
}
Also used : TException(org.apache.thrift.TException) TProtocol(org.apache.thrift.protocol.TProtocol) TMap(org.apache.thrift.protocol.TMap)

Example 19 with TMap

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;
}
Also used : TField(org.apache.thrift.protocol.TField) HashMap(java.util.HashMap) TMap(org.apache.thrift.protocol.TMap) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Aggregations

TMap (org.apache.thrift.protocol.TMap)19 HashMap (java.util.HashMap)5 Map (java.util.Map)5 TField (org.apache.thrift.protocol.TField)5 TList (org.apache.thrift.protocol.TList)5 TSet (org.apache.thrift.protocol.TSet)4 Properties (java.util.Properties)3 Configuration (org.apache.hadoop.conf.Configuration)3 TCTLSeparatedProtocol (org.apache.hadoop.hive.serde2.thrift.TCTLSeparatedProtocol)3 TConfiguration (org.apache.thrift.TConfiguration)3 TException (org.apache.thrift.TException)3 TMemoryBuffer (org.apache.thrift.transport.TMemoryBuffer)3 Test (org.junit.Test)3 EnumMap (java.util.EnumMap)2 PList (net.morimekta.providence.descriptor.PList)2 PMap (net.morimekta.providence.descriptor.PMap)2 PSet (net.morimekta.providence.descriptor.PSet)2 TStruct (org.apache.thrift.protocol.TStruct)2 JsonElement (com.google.gson.JsonElement)1 JsonStreamParser (com.google.gson.JsonStreamParser)1