org.apache.thrift.protocol.TMap Java Examples

The following examples show how to use org.apache.thrift.protocol.TMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ThriftProtocolAgentIntercept.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
public static void writeFieldStop(final Object protocol) throws TException {
  if (injected.get())
    return;

  final TProtocol tProtocol = (TProtocol)protocol;
  final Span span = spanHolder.get();
  if (span == null)
    return;

  final Map<String,String> map = new HashMap<>();
  GlobalTracer.get().inject(span.context(), Builtin.TEXT_MAP, new TextMapAdapter(map));

  tProtocol.writeFieldBegin(new TField("span", TType.MAP, SPAN_FIELD_ID));
  tProtocol.writeMapBegin(new TMap(TType.STRING, TType.STRING, map.size()));
  for (final Entry<String,String> entry : map.entrySet()) {
    tProtocol.writeString(entry.getKey());
    tProtocol.writeString(entry.getValue());
  }

  tProtocol.writeMapEnd();
  tProtocol.writeFieldEnd();
  injected.set(true);
}
 
Example #2
Source File: BufferedProtocolReadToWrite.java    From parquet-mr with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: TTextProtocol.java    From armeria with Apache License 2.0 6 votes vote down vote up
@Override
public TMap readMapBegin() throws TException {
    getCurrentContext().read();

    JsonNode curElem = getCurrentContext().getCurrentChild();

    if (getCurrentContext().isMapKey()) {
        try {
            curElem = OBJECT_MAPPER.readTree(curElem.asText());
        } catch (IOException e) {
            throw new TException("Could not parse map key, is it valid json?", e);
        }
    }

    if (!curElem.isObject()) {
        throw new TException("Expected JSON Object!");
    }

    pushContext(new MapContext(curElem));

    return new TMap(UNUSED_TYPE, UNUSED_TYPE, curElem.size());
}
 
Example #4
Source File: DefaultEventsVisitor.java    From parquet-mr with Apache License 2.0 6 votes vote down vote up
@Override
public Void visit(ThriftType.MapType mapType, Void v) {
   dummyEvents.add(new ParquetProtocol("readMapBegin()") {
     @Override
     public TMap readMapBegin() throws TException {
       return new TMap();
     }
   });

  dummyEvents.add(new ParquetProtocol("readMapEnd()") {
    @Override
    public void readMapEnd() throws TException {
    }
  });
  return null;
}
 
Example #5
Source File: ProtocolReadToWrite.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
private void readOneMap(TProtocol in, TProtocol out) throws TException {
  final TMap map = in.readMapBegin();
  out.writeMapBegin(map);
  for (int i = 0; i < map.size; i++) {
    readOneValue(in, out, map.keyType);
    readOneValue(in, out, map.valueType);
  }
  in.readMapEnd();
  out.writeMapEnd();
}
 
Example #6
Source File: TSimpleJSONProtocol.java    From nettythrift with Apache License 2.0 5 votes vote down vote up
public void writeMapBegin(TMap map) throws TException {
	assertContextIsNotMapKey(MAP);
	writeContext_.write();
	trans_.write(LBRACE);
	pushWriteContext(new MapContext());
	// No metadata!
}
 
Example #7
Source File: TSimpleJSONProtocol.java    From nettythrift with Apache License 2.0 5 votes vote down vote up
public TMap readMapBegin() throws TException {
	BaseArray prevStruct = structStack.peek();
	BaseArray obj = prevStruct.getArray();
	structStack.push(obj);

	MapMetaData mm = (MapMetaData) obj.getMetaData();
	return new TMap(mm.keyMetaData.type, mm.valueMetaData.type, obj.length());
}
 
Example #8
Source File: MapTypeAdapterFactory.java    From Firefly with Apache License 2.0 5 votes vote down vote up
@Override
public void write(Map<?, ?> map, TProtocol protocol) throws TException {
    protocol.writeMapBegin(new TMap(keyTypeAdapter.getTType(), valueTypeAdapter.getTType(), map.size()));
    for (Map.Entry entry : map.entrySet()) {
        keyTypeAdapter.write(entry.getKey(), protocol);
        valueTypeAdapter.write(entry.getValue(), protocol);
    }
    protocol.writeMapEnd();
}
 
Example #9
Source File: MapTypeAdapterFactory.java    From Firefly with Apache License 2.0 5 votes vote down vote up
@Override
public Map<?, ?> read(TProtocol protocol) throws TException {
    TMap tmap = protocol.readMapBegin();
    HashMap hashMap = new HashMap(tmap.size);
    for (int i = 0, n = tmap.size; i < n; i++) {
        Object key = keyTypeAdapter.read(protocol);
        Object value = valueTypeAdapter.read(protocol);
        hashMap.put(key, value);
    }
    protocol.readMapEnd();
    return hashMap;
}
 
Example #10
Source File: ParquetWriteProtocol.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
@Override
public void writeMapBegin(TMap map) throws TException {
  start();
  recordConsumer.startGroup();
  countToConsume = map.size;
  if (countToConsume > 0) {
    recordConsumer.startField(mapContent.getType().getName(), 0);
    currentProtocol = keyProtocol;
  }
}
 
Example #11
Source File: ThriftRecordConverter.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
@Override
public void end() {
  final int count = child.getCount();
  parentEvents.add(new ParquetProtocol("readMapBegin()") {
    @Override
    public TMap readMapBegin() throws TException {
      return new TMap(keyType, valueType, count);
    }
  });
  parentEvents.addAll(mapEvents);
  mapEvents.clear();
  parentEvents.add(readMapEnd);
}
 
Example #12
Source File: EventBasedThriftReader.java    From parquet-format with Apache License 2.0 5 votes vote down vote up
/**
 * reads the map content (key values) from the underlying protocol and passes the events to the map event consumer
 * @param eventConsumer the consumer
 * @param tMap the map descriptor
 * @throws TException
 */
public void readMapContent(MapConsumer eventConsumer, TMap tMap)
    throws TException {
  for (int i = 0; i < tMap.size; i++) {
    eventConsumer.consumeEntry(protocol, this, tMap.keyType, tMap.valueType);
  }
}
 
Example #13
Source File: EventBasedThriftReader.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
/**
 * reads the map content (key values) from the underlying protocol and passes the events to the map event consumer
 * @param eventConsumer the consumer
 * @param tMap the map descriptor
 * @throws TException if any thrift related error occurs during the reading
 */
public void readMapContent(MapConsumer eventConsumer, TMap tMap)
    throws TException {
  for (int i = 0; i < tMap.size; i++) {
    eventConsumer.consumeEntry(protocol, this, tMap.keyType, tMap.valueType);
  }
}
 
Example #14
Source File: ParquetReadProtocol.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
public TMap readMapBegin() throws TException {
  LOG.debug("readMapBegin()");
  return next().readMapBegin();
}
 
Example #15
Source File: BufferedProtocolReadToWrite.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
@Override
public void writeMapBegin(TMap tMap) throws TException {
}
 
Example #16
Source File: BufferedProtocolReadToWrite.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
@Override
public TMap readMapBegin() throws TException {
  return null;
}
 
Example #17
Source File: ParquetProtocol.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
@Override
public void writeMapBegin(TMap map) throws TException {
  throw exception();
}
 
Example #18
Source File: ParquetProtocol.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
@Override
public TMap readMapBegin() throws TException {
  throw exception();
}
 
Example #19
Source File: ThriftSampleData.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public void write(TProtocol oprot, ThriftSampleData struct)
    throws TException {
  struct.validate();
  oprot.writeStructBegin(ThriftSampleData.STRUCT_DESC);
  if (struct.isSetId()) {
    oprot.writeFieldBegin(ThriftSampleData.ID_FIELD_DESC);
    oprot.writeI32(struct.id);
    oprot.writeFieldEnd();
  }

  if (struct.name != null && struct.isSetName()) {
    oprot.writeFieldBegin(ThriftSampleData.NAME_FIELD_DESC);
    oprot.writeString(struct.name);
    oprot.writeFieldEnd();
  }

  if (struct.isSetCreated_at()) {
    oprot.writeFieldBegin(ThriftSampleData.CREATED_AT_FIELD_DESC);
    oprot.writeI64(struct.created_at);
    oprot.writeFieldEnd();
  }

  if (struct.isSetActive()) {
    oprot.writeFieldBegin(ThriftSampleData.ACTIVE_FIELD_DESC);
    oprot.writeBool(struct.active);
    oprot.writeFieldEnd();
  }

  Iterator var3;
  if (struct.groups != null) {
    oprot.writeFieldBegin(ThriftSampleData.GROUPS_FIELD_DESC);
    oprot.writeListBegin(new TList((byte) 6, struct.groups.size()));
    var3 = struct.groups.iterator();

    while (var3.hasNext()) {
      short _iter10 = ((Short) var3.next()).shortValue();
      oprot.writeI16(_iter10);
    }

    oprot.writeListEnd();
    oprot.writeFieldEnd();
  }

  if (struct.map_values != null) {
    oprot.writeFieldBegin(ThriftSampleData.MAP_VALUES_FIELD_DESC);
    oprot.writeMapBegin(new TMap((byte) 11, (byte) 10, struct.map_values.size()));
    var3 = struct.map_values.entrySet().iterator();

    while (var3.hasNext()) {
      Entry<String, Long> _iter11 = (Entry) var3.next();
      oprot.writeString((String) _iter11.getKey());
      oprot.writeI64(((Long) _iter11.getValue()).longValue());
    }

    oprot.writeMapEnd();
    oprot.writeFieldEnd();
  }

  if (struct.set_values != null) {
    oprot.writeFieldBegin(ThriftSampleData.SET_VALUES_FIELD_DESC);
    oprot.writeSetBegin(new TSet((byte) 11, struct.set_values.size()));
    var3 = struct.set_values.iterator();

    while (var3.hasNext()) {
      String _iter12 = (String) var3.next();
      oprot.writeString(_iter12);
    }

    oprot.writeSetEnd();
    oprot.writeFieldEnd();
  }

  oprot.writeFieldStop();
  oprot.writeStructEnd();
}
 
Example #20
Source File: TReplaceListProtocol.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@Override
public void writeMapBegin(TMap map) throws TException {
    if (!writeFieldBegin) {
        protocol.writeMapBegin(map);
    }
}
 
Example #21
Source File: TReplaceListProtocol.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@Override
public TMap readMapBegin() throws TException {
    throw new TException("unsupported operation");
}
 
Example #22
Source File: ThriftSampleData.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public void read(TProtocol prot, ThriftSampleData struct)
    throws TException {
  TTupleProtocol iprot = (TTupleProtocol) prot;
  BitSet incoming = iprot.readBitSet(7);
  if (incoming.get(0)) {
    struct.id = iprot.readI32();
    struct.setIdIsSet(true);
  }

  if (incoming.get(1)) {
    struct.name = iprot.readString();
    struct.setNameIsSet(true);
  }

  if (incoming.get(2)) {
    struct.created_at = iprot.readI64();
    struct.setCreated_atIsSet(true);
  }

  if (incoming.get(3)) {
    struct.active = iprot.readBool();
    struct.setActiveIsSet(true);
  }

  int _i25;
  if (incoming.get(4)) {
    TList _list16 = new TList((byte) 6, iprot.readI32());
    struct.groups = new ArrayList(_list16.size);

    for (_i25 = 0; _i25 < _list16.size; ++_i25) {
      short _elem17 = iprot.readI16();
      struct.groups.add(_elem17);
    }

    struct.setGroupsIsSet(true);
  }

  String _elem24;
  if (incoming.get(5)) {
    TMap _map19 = new TMap((byte) 11, (byte) 10, iprot.readI32());
    struct.map_values = new HashMap(2 * _map19.size);

    for (int _i22 = 0; _i22 < _map19.size; ++_i22) {
      _elem24 = iprot.readString();
      long _val21 = iprot.readI64();
      struct.map_values.put(_elem24, _val21);
    }

    struct.setMap_valuesIsSet(true);
  }

  if (incoming.get(6)) {
    TSet _set23 = new TSet((byte) 11, iprot.readI32());
    struct.set_values = new HashSet(2 * _set23.size);

    for (_i25 = 0; _i25 < _set23.size; ++_i25) {
      _elem24 = iprot.readString();
      struct.set_values.add(_elem24);
    }

    struct.setSet_valuesIsSet(true);
  }
}
 
Example #23
Source File: MappedFileTBinaryProtocol.java    From singer with Apache License 2.0 4 votes vote down vote up
public TMap readMapBegin() throws TException {
  TMap map = new TMap(readByte(), readByte(), readI32());
  checkContainerReadLength(map.size);
  return map;
}
 
Example #24
Source File: ParquetWriteProtocol.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 * @see org.apache.parquet.thrift.ParquetProtocol#writeMapBegin(org.apache.thrift.protocol.TMap)
 */
@Override
public void writeMapBegin(TMap map) throws TException {
  if (LOG.isDebugEnabled()) LOG.debug("writeMapBegin("+toString(map)+")");
  currentProtocol.writeMapBegin(map);
}
 
Example #25
Source File: ParquetWriteProtocol.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
private String toString(TMap map) {
  return "<TMap keyType:" + map.keyType + " valueType:" + map.valueType + " size:" + map.size + ">";
}
 
Example #26
Source File: TypedConsumer.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
public void consumeMap(TProtocol protocol, EventBasedThriftReader reader, TMap tMap) throws TException {
  reader.readMapContent(this, tMap);
}
 
Example #27
Source File: InterningProtocol.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
public TMap readMapBegin() throws TException {
  return delegate.readMapBegin();
}
 
Example #28
Source File: InterningProtocol.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
public void writeMapBegin(TMap map) throws TException {
  delegate.writeMapBegin(map);
}
 
Example #29
Source File: TypedConsumer.java    From parquet-format with Apache License 2.0 4 votes vote down vote up
public void consumeMap(TProtocol protocol, EventBasedThriftReader reader, TMap tMap) throws TException {
  reader.readMapContent(this, tMap);
}
 
Example #30
Source File: InterningProtocol.java    From parquet-format with Apache License 2.0 4 votes vote down vote up
public TMap readMapBegin() throws TException {
  return delegate.readMapBegin();
}