Search in sources :

Example 1 with SumAccumulation

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);
}
Also used : AccumulationTag(org.apache.apex.malhar.lib.window.accumulation.CompositeAccumulation.AccumulationTag) SumAccumulation(org.apache.apex.malhar.lib.window.SumAccumulation) List(java.util.List) Test(org.junit.Test)

Example 2 with SumAccumulation

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);
}
Also used : WindowState(org.apache.apex.malhar.lib.window.WindowState) SumAccumulation(org.apache.apex.malhar.lib.window.SumAccumulation) WindowOption(org.apache.apex.malhar.lib.window.WindowOption) KeyedWindowedOperatorImpl(org.apache.apex.malhar.lib.window.impl.KeyedWindowedOperatorImpl) ConsoleOutputOperator(org.apache.apex.malhar.lib.io.ConsoleOutputOperator) MutableLong(org.apache.commons.lang3.mutable.MutableLong) MutableLong(org.apache.commons.lang3.mutable.MutableLong)

Aggregations

SumAccumulation (org.apache.apex.malhar.lib.window.SumAccumulation)2 List (java.util.List)1 ConsoleOutputOperator (org.apache.apex.malhar.lib.io.ConsoleOutputOperator)1 WindowOption (org.apache.apex.malhar.lib.window.WindowOption)1 WindowState (org.apache.apex.malhar.lib.window.WindowState)1 AccumulationTag (org.apache.apex.malhar.lib.window.accumulation.CompositeAccumulation.AccumulationTag)1 KeyedWindowedOperatorImpl (org.apache.apex.malhar.lib.window.impl.KeyedWindowedOperatorImpl)1 MutableLong (org.apache.commons.lang3.mutable.MutableLong)1 Test (org.junit.Test)1