@Test public void useUnEscapeInvalidEscapeString() throws Exception { ConfigSource config = this.config.deepCopy().set("invalid_string_escapes", "UNESCAPE"); transaction(config, fileInput( "{\"\\a\":\"b\"}\\" )); List<Object[]> records = Pages.toObjects(plugin.newSchema(), output.pages); assertEquals(1, records.size()); Object[] record = records.get(0); Map<Value, Value> map = ((Value) record[0]).asMapValue().map(); assertEquals(newString("b"), map.get(newString("a"))); }
Value visitMap(String rootPath, MapValue mapValue) int size = mapValue.size(); int i = 0; ArrayList<Value> newValue = new ArrayList<>(size * 2); if (this.jsonDropColumns.containsKey(rootPath)) { HashSet<String> jsonDropColumns = this.jsonDropColumns.get(rootPath); for (Map.Entry<Value, Value> entry : mapValue.entrySet()) { Value k = entry.getKey(); Value v = entry.getValue(); Map<Value, Value> map = mapValue.map(); for (JsonColumn jsonColumn : this.jsonColumns.get(rootPath).values()) { Value src = jsonColumn.getSrcTailNameValue(); for (Map.Entry<Value, Value> entry : mapValue.entrySet()) { Value k = entry.getKey(); Value v = entry.getValue(); Map<Value, Value> map = mapValue.map(); for (JsonColumn jsonColumn : this.jsonAddColumns.get(rootPath).values()) { Value k = jsonColumn.getTailNameValue();
private Map<Object, Object> deserializeMap( ModuleDescriptor module, MapType mapType, MapValue value ) throws IOException { Map<Object, Object> map = new LinkedHashMap<>( value.size() ); for( Map.Entry<Value, Value> entry : value.entrySet() ) { Object key = doDeserialize( module, mapType.keyType(), entry.getKey() ); Object val = doDeserialize( module, mapType.valueType(), entry.getValue() ); map.put( key, val ); } return map; }
MapValue mapValue = value.asMapValue(); Optional<String> typeInfo = mapValue .entrySet().stream() .filter( entry -> entry.getKey().isStringValue() ) .map( entry ->
static Config buildStoreParams(ConfigFactory cf, TDJobOperator j, boolean storeLastResults, TaskState state, DurationInterval retryInterval) { if (storeLastResults) { Config td = cf.create(); List<ArrayValue> results = downloadFirstResults(j, 1, state, RESULT, retryInterval); Map<RawValue, Value> map = new LinkedHashMap<>(); if (!results.isEmpty()) { ArrayValue row = results.get(0); List<String> columnNames = j.getResultColumnNames(); for (int i = 0; i < Math.min(row.size(), columnNames.size()); i++) { map.put(ValueFactory.newString(columnNames.get(i)), row.get(i)); } } MapValue lastResults = ValueFactory.newMap(map); try { td.set("last_results", new ObjectMapper().readTree(lastResults.toJson())); } catch (IOException ex) { throw Throwables.propagate(ex); } return cf.create().set("td", td); } else { return cf.create(); } }
@Test public void useSkipInvalidEscapeString() throws Exception { ConfigSource config = this.config.deepCopy().set("invalid_string_escapes", "SKIP"); transaction(config, fileInput( "{\"\\a\":\"b\"}\\" )); List<Object[]> records = Pages.toObjects(plugin.newSchema(), output.pages); assertEquals(1, records.size()); Object[] record = records.get(0); Map<Value, Value> map = ((Value) record[0]).asMapValue().map(); assertEquals(newString("b"), map.get(newString(""))); }
HttpEntity messageEntity = httpResponse.getEntity(); if (messageEntity != null) { MessagePack msgpack = new MessagePack(); MessageUnpacker u = msgpack.newUnpacker(messageEntity.getContent()); MapValue mv = (MapValue) u.unpackValue(); Map<Value, Value> map = mv.map();
@Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof Value)) { return false; } Value v = (Value) o; if (!v.isMapValue()) { return false; } MapValue mv = v.asMapValue(); return map().equals(mv.map()); }
MapValue value ) throws IOException Map<String, Value> namedValues = value.map().entrySet().stream().map( entry ->
@Test public void ingestWithAck() throws IOException { FluentdIngester.Config config = new FluentdIngester.Config(); config.setAckResponseMode(true); Ingester ingester = new FluentdIngester(config, fluentdSender); ingester.ingest(TAG, ByteBuffer.wrap(DATA)); ArgumentCaptor<byte[]> ackTokenArgumentCaptor = ArgumentCaptor.forClass(byte[].class); verify(fluentdSender, times(1)) .sendWithAck(byteBuffersArgumentCaptor.capture(), ackTokenArgumentCaptor.capture()); List<ByteBuffer> byteBuffers = byteBuffersArgumentCaptor.getAllValues().get(0); byte[] ingested = getIngestedData(byteBuffers); MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(ingested); ImmutableArrayValue arrayValue = unpacker.unpackValue().asArrayValue(); assertEquals(3, arrayValue.size()); assertEquals(TAG, arrayValue.get(0).asStringValue().asString()); assertArrayEquals(DATA, arrayValue.get(1).asRawValue().asByteArray()); Map<Value, Value> options = arrayValue.get(2).asMapValue().map(); assertEquals(2, options.size()); assertEquals(DATA.length, options.get(ValueFactory.newString("size")).asIntegerValue().asInt()); String ackToken = options.get(ValueFactory.newString("chunk")).asRawValue().asString(); UUID uuidFromAckToken = UUID.fromString(ackToken); List<byte[]> ackTokenArgumentCaptorAllValues = ackTokenArgumentCaptor.getAllValues(); assertEquals(1, ackTokenArgumentCaptorAllValues.size()); assertEquals(uuidFromAckToken, UUID.fromString(new String(ackTokenArgumentCaptorAllValues.get(0), CHARSET))); }
Map<Value, Value> map = rootValue.get(2).asMapValue().map();
@Test public void ingestWithoutAck() throws IOException { Ingester ingester = new FluentdIngester(new FluentdIngester.Config(), fluentdSender); ingester.ingest(TAG, ByteBuffer.wrap(DATA)); verify(fluentdSender, times(1)).send(byteBuffersArgumentCaptor.capture()); List<ByteBuffer> byteBuffers = byteBuffersArgumentCaptor.getAllValues().get(0); byte[] ingested = getIngestedData(byteBuffers); MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(ingested); ImmutableArrayValue arrayValue = unpacker.unpackValue().asArrayValue(); assertEquals(3, arrayValue.size()); assertEquals(TAG, arrayValue.get(0).asStringValue().asString()); assertArrayEquals(DATA, arrayValue.get(1).asRawValue().asByteArray()); Map<Value, Value> options = arrayValue.get(2).asMapValue().map(); assertEquals(1, options.size()); assertEquals(DATA.length, options.get(ValueFactory.newString("size")).asIntegerValue().asInt()); }