@Override public ValueMap asMap() throws ValueTranslationException { ValueMap map = ValueFactory.createMap(); map.put(key, asBytes()); return map; }
public static ValueMap create(Map<String, Double> input) { if (input == null) { return null; } if (input instanceof MapStringDouble) { return ((MapStringDouble) input).getData(); } else { ValueMap output = ValueFactory.createMap(); for (Map.Entry<String, Double> entry : input.entrySet()) { output.put(entry.getKey(), ValueFactory.create(entry.getValue())); } return output; } }
public static ValueMap create(Map<String, String> input) { if (input == null) { return null; } if (input instanceof MapStringString) { return ((MapStringString) input).getData(); } else { ValueMap output = ValueFactory.createMap(); for (Map.Entry<String, String> entry : input.entrySet()) { output.put(entry.getKey(), ValueFactory.create(entry.getValue())); } return output; } }
public static ValueMap create(Map<String, byte[]> input) { if (input == null) { return null; } if (input instanceof MapStringBytes) { return ((MapStringBytes) input).getData(); } else { ValueMap output = ValueFactory.createMap(); for (Map.Entry<String, byte[]> entry : input.entrySet()) { output.put(entry.getKey(), ValueFactory.create(entry.getValue())); } return output; } }
public static ValueMap create(Map<String, List<String>> input) { if (input == null) { return null; } if (input instanceof MapStringListString) { return ((MapStringListString) input).getData(); } else { ValueMap output = ValueFactory.createMap(); for (Entry<String, List<String>> entry : input.entrySet()) { output.put(entry.getKey(), ListString.create(entry.getValue())); } return output; } }
public MapStringDouble(ValueMap map, boolean copy) { if (copy) { this.data = ValueFactory.createMap(); for (ValueMapEntry entry : map) { this.data.put(entry.getKey(), entry.getValue()); } } else { this.data = map; } }
public MapStringLong(ValueMap map, boolean copy) { if (copy) { this.data = ValueFactory.createMap(); for (ValueMapEntry entry : map) { this.data.put(entry.getKey(), entry.getValue()); } } else { this.data = map; } }
public MapStringBytes(ValueMap map, boolean copy) { if (copy) { this.data = ValueFactory.createMap(); for (ValueMapEntry entry : map) { this.data.put(entry.getKey(), entry.getValue()); } } else { this.data = map; } }
public MapStringString(ValueMap map, boolean copy) { if (copy) { this.data = ValueFactory.createMap(); for (ValueMapEntry entry : map) { this.data.put(entry.getKey(), entry.getValue()); } } else { this.data = map; } }
@Override public ValueMap asMap() throws ValueTranslationException { try { ValueMap map = ValueFactory.createMap(); map.put("b", ValueFactory.create(CodecBin2.encodeBytes(heldObject))); return map; } catch (Exception ex) { throw new ValueTranslationException(ex); } }
public ValueFilterMap setMap(HashMap<String, String> map) { ValueMap newMap = ValueFactory.createMap(); map.forEach((k, v) -> { newMap.put(k, ValueFactory.create(v)); }); this.map = new ConstantField(newMap); return this; }
private static ValueMap createMap(String... kvPairs) { ValueMap valueMap = ValueFactory.createMap(); for (String kvPair : kvPairs) { String[] kv = kvPair.split("="); valueMap.put(kv[0], ValueFactory.create(kv[1])); } return valueMap; } }
@Override public ValueMap asMap() throws ValueTranslationException { ValueMap map = ValueFactory.createMap(); int bound = heldObject.byteSize(); ByteBuffer buf = ByteBuffer.allocate(bound); heldObject.asSmallBytes(buf); map.put("q", ValueFactory.create(quantile)); map.put("o", ValueFactory.create(op.toString())); map.put("b", ValueFactory.create(buf.array())); return map; }
private static ValueMap multisetToValueMap(Multiset<String> matches) { ValueMap valueMap = ValueFactory.createMap(); for (Multiset.Entry<String> match : matches.entrySet()) { valueMap.put(match.getElement(), ValueFactory.create(match.getCount())); } return valueMap; } }
@Test public void mapTest() { ValueFilterJoin join = new ValueFilterJoin(); ValueMap map = ValueFactory.createMap(ImmutableMap.of( "b", Arrays.asList("p", "q"), "a", Arrays.asList("x", "y", "z"), "c", Arrays.asList("c", "d", "e") )); join.setJoin(";"); assertEquals("should correctly join map", "a=[x, y, z];b=[p, q];c=[c, d, e]", join.filter(map).toString()); } }
@Before public void setup() throws IOException { emitter = mock(StreamEmitter.class); bundle = new ListBundle(); map = ValueFactory.createMap(); builder = Configs.decodeObject(StreamMapSplitBuilder.class, "field: foo, keyField: key, valueField: value"); }
@Test public void printMap() throws IOException { ValueFilterPrettyPrint vf = Configs.decodeObject(ValueFilterPrettyPrint.class, ""); ValueMap map = ValueFactory.createMap(); test(vf, map, "{}"); map.put("foo", ValueFactory.create(1)); map.put("bar", ValueFactory.create("baz\"quux")); test(vf, map, ImmutableSet.of("{\"foo\":1,\"bar\":\"baz\\\"quux\"}", "{\"bar\":\"baz\\\"quux\",\"foo\":1}")); }
@Test public void putField() throws Exception { ValueObject value = applyFilter("{key.field: somekey, put.field: somevalue}"); ValueMap result = ValueFactory.createMap(); result.put("a", ValueFactory.create(1)); result.put("b", ValueFactory.create(10)); result.put("c", ValueFactory.create("test")); assertEquals(value, result); } }
@Test public void put() throws Exception { ValueObject value = applyFilter("{key: z, put: 0}"); ValueMap result = ValueFactory.createMap(); result.put("a", ValueFactory.create(1)); result.put("b", ValueFactory.create(2)); result.put("c", ValueFactory.create("test")); result.put("z", ValueFactory.create(0)); assertEquals(value, result); }
@Test public void parseMap() throws IOException { ValueMap map = ValueFactory.createMap(); assertEquals(map, json.filterValue(ValueFactory.create("{}"))); roundTrip(map); map.put("foo", ValueFactory.create(1)); map.put("bar", ValueFactory.create("baz\"quux")); assertEquals(map, json.filterValue(ValueFactory.create("{\"foo\":1,\"bar\":\"baz\\\"quux\"}"))); roundTrip(map); }