use of org.apache.apex.malhar.lib.window.SumAccumulation in project apex-malhar by apache.
the class CompositeAccumulationTest method testIncremental.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testIncremental() {
CompositeAccumulation<Long> accumulations = new CompositeAccumulation<>();
AccumulationTag sumTag = accumulations.addAccumulation((Accumulation) new SumAccumulation());
AccumulationTag countTag = accumulations.addAccumulation((Accumulation) new Count());
AccumulationTag maxTag = accumulations.addAccumulation(new Max());
AccumulationTag minTag = accumulations.addAccumulation(new Min());
List values = accumulations.defaultAccumulatedValue();
for (long i = 1; i <= 10; i++) {
values = accumulations.accumulate(values, i);
}
List outputValues = accumulations.getOutput(values);
Assert.assertTrue((Long) accumulations.getSubOutput(sumTag, outputValues) == 55L);
Assert.assertTrue((Long) accumulations.getSubOutput(countTag, outputValues) == 10L);
Assert.assertTrue((Long) accumulations.getSubOutput(maxTag, outputValues) == 10L);
Assert.assertTrue((Long) accumulations.getSubOutput(minTag, outputValues) == 1L);
}
use of org.apache.apex.malhar.lib.window.SumAccumulation in project apex-malhar by apache.
the class Application method populateDAG.
@Override
public void populateDAG(DAG dag, Configuration configuration) {
WordGenerator inputOperator = new WordGenerator();
KeyedWindowedOperatorImpl<String, Long, MutableLong, Long> windowedOperator = new KeyedWindowedOperatorImpl<>();
Accumulation<Long, MutableLong, Long> sum = new SumAccumulation();
windowedOperator.setAccumulation(sum);
windowedOperator.setDataStorage(new InMemoryWindowedKeyedStorage<String, MutableLong>());
windowedOperator.setRetractionStorage(new InMemoryWindowedKeyedStorage<String, Long>());
windowedOperator.setWindowStateStorage(new InMemoryWindowedStorage<WindowState>());
windowedOperator.setWindowOption(new WindowOption.TimeWindows(Duration.standardMinutes(1)));
windowedOperator.setTriggerOption(TriggerOption.AtWatermark().withEarlyFiringsAtEvery(Duration.millis(1000)).accumulatingAndRetractingFiredPanes());
// windowedOperator.setAllowedLateness(Duration.millis(14000));
ConsoleOutputOperator outputOperator = new ConsoleOutputOperator();
dag.addOperator("inputOperator", inputOperator);
dag.addOperator("windowedOperator", windowedOperator);
dag.addOperator("outputOperator", outputOperator);
dag.addStream("input_windowed", inputOperator.output, windowedOperator.input);
dag.addStream("windowed_output", windowedOperator.output, outputOperator.input);
}
Aggregations