@Test public void emitOriginal() throws IOException { map.put("hello", ValueFactory.create("boo")); map.put("hi", ValueFactory.create("hoo")); bundle.setValue(bundle.getFormat().getField("foo"), map); bundle.setValue(bundle.getFormat().getField("bar"), ValueFactory.create("biz")); builder = Configs.decodeObject(StreamMapSplitBuilder.class, "field: foo, keyField: key, valueField: value, emitOriginal: true"); builder.process(bundle, emitter); ArgumentCaptor<Bundle> bundleCapture = ArgumentCaptor.forClass(Bundle.class); verify(emitter, times(3)).emit(bundleCapture.capture()); List<Bundle> newBundles = bundleCapture.getAllValues(); int originalSeen = 0; for (Bundle b : newBundles) { if (b.getValue(b.getFormat().getField("key")) == null) { originalSeen++; assertEquals("biz", b.getValue(b.getFormat().getField("bar")).asString().asNative()); assertNull(b.getValue(b.getFormat().getField("foo"))); } } assertEquals(1, originalSeen); }
@Override public void process(Bundle bundle, StreamEmitter emitter) { ValueObject obj = field.getValue(bundle); field.removeValue(bundle); if ((obj != null) && (obj.getObjectType() == ValueObject.TYPE.MAP)) { ValueMap map = obj.asMap(); for (ValueMapEntry entry : map) { Bundle newBundle = Bundles.deepCopyBundle(bundle); keyField.setValue(newBundle, ValueFactory.create(entry.getKey())); valueField.setValue(newBundle, entry.getValue()); if (emitFilter == null || emitFilter.filter(newBundle)) { emitter.emit(newBundle); } } } if (emitOriginal && (emitFilter == null || emitFilter.filter(bundle))) { emitter.emit(bundle); } }
StreamMapSplitBuilder extends StreamBuilder { @Override public void process(Bundle bundle, StreamEmitter emitter) { ValueObject obj = field.getValue(bundle); field.removeValue(bundle); if ((obj != null) && (obj.getObjectType() == ValueObject.TYPE.MAP)) { ValueMap map = obj.asMap(); for (ValueMapEntry entry : map) { Bundle newBundle = Bundles.deepCopyBundle(bundle); keyField.setValue(newBundle, ValueFactory.create(entry.getKey())); valueField.setValue(newBundle, entry.getValue()); if (emitFilter == null || emitFilter.filter(newBundle)) { emitter.emit(newBundle); } } } if (emitOriginal && (emitFilter == null || emitFilter.filter(bundle))) { emitter.emit(bundle); } } }
StreamMapSplitBuilder extends StreamBuilder { @Override public void process(Bundle bundle, StreamEmitter emitter) { ValueObject obj = field.getValue(bundle); field.removeValue(bundle); if ((obj != null) && (obj.getObjectType() == ValueObject.TYPE.MAP)) { ValueMap map = obj.asMap(); for (ValueMapEntry entry : map) { Bundle newBundle = Bundles.deepCopyBundle(bundle); keyField.setValue(newBundle, ValueFactory.create(entry.getKey())); valueField.setValue(newBundle, entry.getValue()); if (emitFilter == null || emitFilter.filter(newBundle)) { emitter.emit(newBundle); } } } if (emitOriginal && (emitFilter == null || emitFilter.filter(bundle))) { emitter.emit(bundle); } }  }
StreamMapSplitBuilder extends StreamBuilder { @Override public void process(Bundle bundle, StreamEmitter emitter) { ValueObject obj = field.getValue(bundle); field.removeValue(bundle); if ((obj != null) && (obj.getObjectType() == ValueObject.TYPE.MAP)) { ValueMap map = obj.asMap(); for (ValueMapEntry entry : map) { Bundle newBundle = Bundles.deepCopyBundle(bundle); keyField.setValue(newBundle, ValueFactory.create(entry.getKey())); valueField.setValue(newBundle, entry.getValue()); if (emitFilter == null || emitFilter.filter(newBundle)) { emitter.emit(newBundle); } } } if (emitOriginal && (emitFilter == null || emitFilter.filter(bundle))) { emitter.emit(bundle); } }  @Override void init(); @Override void process(Bundle bundle, StreamEmitter emitter); }
StreamMapSplitBuilder extends StreamBuilder { @Override public void process(Bundle bundle, StreamEmitter emitter) { ValueObject obj = field.getValue(bundle); field.removeValue(bundle); if ((obj != null) && (obj.getObjectType() == ValueObject.TYPE.MAP)) { ValueMap map = obj.asMap(); for (ValueMapEntry entry : map) { Bundle newBundle = Bundles.deepCopyBundle(bundle); keyField.setValue(newBundle, ValueFactory.create(entry.getKey())); valueField.setValue(newBundle, entry.getValue()); if (emitFilter == null || emitFilter.filter(newBundle)) { emitter.emit(newBundle); } } } if (emitOriginal && (emitFilter == null || emitFilter.filter(bundle))) { emitter.emit(bundle); } }  @Override void init(); @Override void process(Bundle bundle, StreamEmitter emitter);  }