use of org.apache.apex.malhar.lib.window.Window in project apex-malhar by apache.
the class WindowedMergeOperatorTest method windowedMergeOperatorMergeTest.
@Test
public void windowedMergeOperatorMergeTest() {
WindowedMergeOperatorImpl<Integer, Integer, List<Set<Integer>>, List<List<Integer>>> op = createDefaultWindowedMergeOperator();
Window global = Window.GlobalWindow.INSTANCE;
op.setDataStorage(new InMemoryWindowedStorage<List<Set<Integer>>>());
op.setWindowOption(new WindowOption.GlobalWindow());
op.initializeWindowStates(AbstractWindowedOperator.GLOBAL_WINDOW_SINGLETON_SET);
op.processTuple(new Tuple.WindowedTuple<Integer>(global, 100));
Assert.assertEquals(1, op.dataStorage.get(global).get(0).size());
op.processTuple2(new Tuple.WindowedTuple<Integer>(global, 200));
Assert.assertEquals(1, op.dataStorage.get(global).get(1).size());
op.processTuple(new Tuple.WindowedTuple<Integer>(global, 300));
Assert.assertEquals(2, op.dataStorage.get(global).get(0).size());
Assert.assertEquals(2, op.accumulation.getOutput(op.dataStorage.get(global)).size());
}
use of org.apache.apex.malhar.lib.window.Window in project apex-malhar by apache.
the class WindowedMergeOperatorTest method keyedWindowedMergeOperatorMergeTest.
@Test
public void keyedWindowedMergeOperatorMergeTest() {
KeyedWindowedMergeOperatorImpl<String, Integer, Integer, List<Set<Integer>>, List<List<Integer>>> op = createDefaultKeyedWindowedMergeOperator();
Window global = Window.GlobalWindow.INSTANCE;
op.setDataStorage(new InMemoryWindowedKeyedStorage<String, List<Set<Integer>>>());
op.setWindowOption(new WindowOption.GlobalWindow());
op.initializeWindowStates(AbstractWindowedOperator.GLOBAL_WINDOW_SINGLETON_SET);
op.processTuple(new Tuple.WindowedTuple<KeyValPair<String, Integer>>(global, new KeyValPair<String, Integer>("A", 100)));
Assert.assertEquals(1, op.dataStorage.get(global, "A").get(0).size());
Assert.assertTrue(op.dataStorage.get(global, "A").get(0).contains(100));
op.processTuple2(new Tuple.WindowedTuple<KeyValPair<String, Integer>>(global, new KeyValPair<String, Integer>("A", 200)));
Assert.assertEquals(1, op.dataStorage.get(global, "A").get(1).size());
Assert.assertTrue(op.dataStorage.get(global, "A").get(1).contains(200));
op.processTuple2(new Tuple.WindowedTuple<KeyValPair<String, Integer>>(global, new KeyValPair<String, Integer>("B", 300)));
Assert.assertEquals(1, op.dataStorage.get(global, "A").get(1).size());
Assert.assertEquals(1, op.dataStorage.get(global, "B").get(1).size());
Assert.assertTrue(op.dataStorage.get(global, "B").get(1).contains(300));
Assert.assertEquals(2, op.accumulation.getOutput(op.dataStorage.get(global, "A")).size());
}
use of org.apache.apex.malhar.lib.window.Window in project apex-malhar by apache.
the class WindowedMergeOperatorTestApplication method assignTestWindow.
public static Window.TimeWindow assignTestWindow(long timestamp) {
long beginTimestamp = timestamp - timestamp % windowDuration;
Window.TimeWindow window = new Window.TimeWindow(beginTimestamp, windowDuration);
if (!windowStateMap.containsWindow(window)) {
windowStateMap.put(window, new WindowState());
}
return window;
}
use of org.apache.apex.malhar.lib.window.Window in project apex-malhar by apache.
the class WindowedOperatorImpl method accumulateTuple.
@Override
public void accumulateTuple(Tuple.WindowedTuple<InputT> tuple) {
for (Window window : tuple.getWindows()) {
// process each window
AccumT accum = dataStorage.get(window);
if (accum == null) {
accum = accumulation.defaultAccumulatedValue();
}
dataStorage.put(window, accumulation.accumulate(accum, tuple.getValue()));
}
}
use of org.apache.apex.malhar.lib.window.Window in project apex-malhar by apache.
the class KeyedWindowedOperatorBenchmarkApp method createUpdatedDataStorage.
protected SpillableSetMultimapImpl<Window, String> createUpdatedDataStorage(Configuration conf, SpillableComplexComponentImpl sccImpl) {
String basePath = getStoreBasePath(conf);
ManagedStateSpillableStateStore store = new ManagedStateSpillableStateStore();
((TFileImpl.DTFileImpl) store.getFileAccess()).setBasePath(basePath);
SpillableSetMultimapImpl<Window, String> dataStorage = new SpillableSetMultimapImpl<Window, String>(store, new byte[] { (byte) 1 }, 0, new GenericSerde<Window>(), new GenericSerde<String>());
return dataStorage;
}
Aggregations