use of org.apache.commons.lang3.mutable.MutableLong in project apex-malhar by apache.
the class WindowedOperatorTest method createDefaultWindowedOperator.
private WindowedOperatorImpl<Long, MutableLong, Long> createDefaultWindowedOperator() {
WindowedOperatorImpl<Long, MutableLong, Long> windowedOperator = new WindowedOperatorImpl<>();
if (useSpillable) {
sccImpl = new SpillableComplexComponentImpl(testMeta.timeStore);
// TODO: We don't yet support Spillable data structures for window state storage because SpillableMapImpl does not yet support iterating over all keys.
windowStateStorage = new InMemoryWindowedStorage<>();
SpillableWindowedPlainStorage<MutableLong> pds = new SpillableWindowedPlainStorage<>();
pds.setSpillableComplexComponent(sccImpl);
plainDataStorage = pds;
SpillableWindowedPlainStorage<Long> prs = new SpillableWindowedPlainStorage<>();
prs.setSpillableComplexComponent(sccImpl);
plainRetractionStorage = prs;
windowedOperator.addComponent("SpillableComplexComponent", sccImpl);
} else {
windowStateStorage = new InMemoryWindowedStorage<>();
plainDataStorage = new InMemoryWindowedStorage<>();
plainRetractionStorage = new InMemoryWindowedStorage<>();
}
windowedOperator.setDataStorage(plainDataStorage);
windowedOperator.setRetractionStorage(plainRetractionStorage);
windowedOperator.setWindowStateStorage(windowStateStorage);
windowedOperator.setAccumulation(new SumAccumulation());
return windowedOperator;
}
use of org.apache.commons.lang3.mutable.MutableLong in project apex-malhar by apache.
the class WindowedOperatorTest method testTrigger2.
private void testTrigger2(boolean firingOnlyUpdatedPanes, boolean testRetraction) {
WindowedOperatorImpl<Long, MutableLong, Long> windowedOperator = createDefaultWindowedOperator();
TriggerOption triggerOption = new TriggerOption().withEarlyFiringsAtEvery(Duration.millis(1000));
if (testRetraction) {
triggerOption.accumulatingAndRetractingFiredPanes();
} else {
triggerOption.accumulatingFiredPanes();
}
if (firingOnlyUpdatedPanes) {
triggerOption.firingOnlyUpdatedPanes();
}
windowedOperator.setTriggerOption(triggerOption);
windowedOperator.setWindowOption(new WindowOption.TimeWindows(Duration.millis(1000)));
CollectorTestSink sink = new CollectorTestSink();
windowedOperator.output.setSink(sink);
windowedOperator.setup(testMeta.operatorContext);
windowedOperator.beginWindow(1);
windowedOperator.processTuple(new Tuple.TimestampedTuple<>(BASE + 100L, 2L));
windowedOperator.processTuple(new Tuple.TimestampedTuple<>(BASE + 200L, 3L));
windowedOperator.endWindow();
Assert.assertTrue("No trigger should be fired yet", sink.collectedTuples.isEmpty());
windowedOperator.beginWindow(2);
windowedOperator.endWindow();
Assert.assertTrue("No trigger should be fired yet", sink.collectedTuples.isEmpty());
windowedOperator.beginWindow(3);
windowedOperator.endWindow();
Assert.assertEquals("There should be exactly one tuple for the time trigger", 1, sink.collectedTuples.size());
Assert.assertEquals(5L, ((Tuple<Long>) sink.collectedTuples.get(0)).getValue().longValue());
sink.collectedTuples.clear();
windowedOperator.beginWindow(4);
windowedOperator.endWindow();
Assert.assertTrue("No trigger should be fired yet", sink.collectedTuples.isEmpty());
windowedOperator.beginWindow(5);
windowedOperator.endWindow();
if (firingOnlyUpdatedPanes) {
Assert.assertTrue("There should not be any trigger since no panes have been updated", sink.collectedTuples.isEmpty());
} else {
if (testRetraction) {
Assert.assertEquals("There should be exactly two tuples for the time trigger", 2, sink.collectedTuples.size());
Assert.assertEquals(-5L, ((Tuple<Long>) sink.collectedTuples.get(0)).getValue().longValue());
Assert.assertEquals(5L, ((Tuple<Long>) sink.collectedTuples.get(1)).getValue().longValue());
} else {
Assert.assertEquals("There should be exactly one tuple for the time trigger", 1, sink.collectedTuples.size());
Assert.assertEquals(5L, ((Tuple<Long>) sink.collectedTuples.get(0)).getValue().longValue());
}
}
windowedOperator.teardown();
}
use of org.apache.commons.lang3.mutable.MutableLong in project apex-malhar by apache.
the class SumTest method SumTest.
@Test
public void SumTest() {
SumInt si = new SumInt();
SumLong sl = new SumLong();
SumFloat sf = new SumFloat();
SumDouble sd = new SumDouble();
Assert.assertEquals(new MutableInt(10), si.accumulate(si.defaultAccumulatedValue(), 10));
Assert.assertEquals(new MutableInt(11), si.accumulate(new MutableInt(1), 10));
Assert.assertEquals(new MutableInt(22), si.merge(new MutableInt(1), new MutableInt(21)));
Assert.assertEquals(new MutableLong(10L), sl.accumulate(sl.defaultAccumulatedValue(), 10L));
Assert.assertEquals(new MutableLong(22L), sl.accumulate(new MutableLong(2L), 20L));
Assert.assertEquals(new MutableLong(41L), sl.merge(new MutableLong(32L), new MutableLong(9L)));
Assert.assertEquals(new MutableFloat(9.0F), sf.accumulate(sf.defaultAccumulatedValue(), 9.0F));
Assert.assertEquals(new MutableFloat(22.5F), sf.accumulate(new MutableFloat(2.5F), 20F));
Assert.assertEquals(new MutableFloat(41.0F), sf.merge(new MutableFloat(33.1F), new MutableFloat(7.9F)));
Assert.assertEquals(new MutableDouble(9.0), sd.accumulate(sd.defaultAccumulatedValue(), 9.0));
Assert.assertEquals(new MutableDouble(22.5), sd.accumulate(new MutableDouble(2.5), 20.0));
Assert.assertEquals(new MutableDouble(41.0), sd.merge(new MutableDouble(33.1), new MutableDouble(7.9)));
}
use of org.apache.commons.lang3.mutable.MutableLong in project apex-malhar by apache.
the class Application method populateDAG.
@Override
public void populateDAG(DAG dag, Configuration configuration) {
RandomNumberPairGenerator inputOperator = new RandomNumberPairGenerator();
WindowedOperatorImpl<MutablePair<Double, Double>, MutablePair<MutableLong, MutableLong>, Double> windowedOperator = new WindowedOperatorImpl<>();
Accumulation<MutablePair<Double, Double>, MutablePair<MutableLong, MutableLong>, Double> piAccumulation = new PiAccumulation();
windowedOperator.setAccumulation(piAccumulation);
windowedOperator.setDataStorage(new InMemoryWindowedStorage<MutablePair<MutableLong, MutableLong>>());
windowedOperator.setWindowStateStorage(new InMemoryWindowedStorage<WindowState>());
windowedOperator.setWindowOption(new WindowOption.GlobalWindow());
windowedOperator.setTriggerOption(TriggerOption.AtWatermark().withEarlyFiringsAtEvery(Duration.millis(1000)).accumulatingFiredPanes());
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);
}
use of org.apache.commons.lang3.mutable.MutableLong in project apex-malhar by apache.
the class ApexWindowedStreamImpl method countByKey.
@Override
public <K, STREAM extends WindowedStream<Tuple.WindowedTuple<KeyValPair<K, Long>>>> STREAM countByKey(Function.ToKeyValue<T, K, Long> convertToKeyValue, Option... opts) {
WindowedStream<Tuple<KeyValPair<K, Long>>> kvstream = map(convertToKeyValue);
KeyedWindowedOperatorImpl<K, Long, MutableLong, Long> keyedWindowedOperator = createKeyedWindowedOperator(new SumLong());
return kvstream.addOperator(keyedWindowedOperator, keyedWindowedOperator.input, keyedWindowedOperator.output, opts);
}
Aggregations