Search in sources :

Example 6 with Window

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());
}
Also used : Window(org.apache.apex.malhar.lib.window.Window) WindowOption(org.apache.apex.malhar.lib.window.WindowOption) List(java.util.List) Tuple(org.apache.apex.malhar.lib.window.Tuple) Test(org.junit.Test)

Example 7 with Window

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());
}
Also used : Window(org.apache.apex.malhar.lib.window.Window) WindowOption(org.apache.apex.malhar.lib.window.WindowOption) List(java.util.List) KeyValPair(org.apache.apex.malhar.lib.util.KeyValPair) Tuple(org.apache.apex.malhar.lib.window.Tuple) Test(org.junit.Test)

Example 8 with Window

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;
}
Also used : Window(org.apache.apex.malhar.lib.window.Window) WindowState(org.apache.apex.malhar.lib.window.WindowState)

Example 9 with 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()));
    }
}
Also used : Window(org.apache.apex.malhar.lib.window.Window)

Example 10 with Window

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;
}
Also used : Window(org.apache.apex.malhar.lib.window.Window) ManagedStateSpillableStateStore(org.apache.apex.malhar.lib.state.spillable.managed.ManagedStateSpillableStateStore) SpillableSetMultimapImpl(org.apache.apex.malhar.lib.state.spillable.SpillableSetMultimapImpl)

Aggregations

Window (org.apache.apex.malhar.lib.window.Window)10 WindowState (org.apache.apex.malhar.lib.window.WindowState)5 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 Tuple (org.apache.apex.malhar.lib.window.Tuple)2 WindowOption (org.apache.apex.malhar.lib.window.WindowOption)2 Test (org.junit.Test)2 SpillableSetMultimapImpl (org.apache.apex.malhar.lib.state.spillable.SpillableSetMultimapImpl)1 ManagedStateSpillableStateStore (org.apache.apex.malhar.lib.state.spillable.managed.ManagedStateSpillableStateStore)1 KeyValPair (org.apache.apex.malhar.lib.util.KeyValPair)1