use of org.apache.samza.operators.windows.Windows in project samza by apache.
the class TestExecutionPlanner method createStreamGraphWithJoinAndWindow.
private StreamGraphImpl createStreamGraphWithJoinAndWindow() {
StreamGraphImpl streamGraph = new StreamGraphImpl(runner, config);
BiFunction msgBuilder = mock(BiFunction.class);
MessageStream m1 = streamGraph.getInputStream("input1", msgBuilder).map(m -> m);
MessageStream m2 = streamGraph.getInputStream("input2", msgBuilder).partitionBy(m -> "haha").filter(m -> true);
MessageStream m3 = streamGraph.getInputStream("input3", msgBuilder).filter(m -> true).partitionBy(m -> "hehe").map(m -> m);
Function mockFn = mock(Function.class);
OutputStream<Object, Object, Object> output1 = streamGraph.getOutputStream("output1", mockFn, mockFn);
OutputStream<Object, Object, Object> output2 = streamGraph.getOutputStream("output2", mockFn, mockFn);
m1.map(m -> m).filter(m -> true).window(Windows.<Object, Object>keyedTumblingWindow(m -> m, Duration.ofMillis(8)));
m2.map(m -> m).filter(m -> true).window(Windows.<Object, Object>keyedTumblingWindow(m -> m, Duration.ofMillis(16)));
m1.join(m2, mock(JoinFunction.class), Duration.ofMillis(1600)).sendTo(output1);
m3.join(m2, mock(JoinFunction.class), Duration.ofMillis(100)).sendTo(output2);
m3.join(m2, mock(JoinFunction.class), Duration.ofMillis(252)).sendTo(output2);
return streamGraph;
}
use of org.apache.samza.operators.windows.Windows in project samza by apache.
the class AppWithGlobalConfigExample method describe.
@Override
public void describe(StreamApplicationDescriptor appDescriptor) {
KafkaSystemDescriptor trackingSystem = new KafkaSystemDescriptor("tracking");
KafkaInputDescriptor<PageViewEvent> inputStreamDescriptor = trackingSystem.getInputDescriptor("pageViewEvent", new JsonSerdeV2<>(PageViewEvent.class));
KafkaOutputDescriptor<KV<String, PageViewCount>> outputStreamDescriptor = trackingSystem.getOutputDescriptor("pageViewEventPerMember", KVSerde.of(new StringSerde(), new JsonSerdeV2<>(PageViewCount.class)));
appDescriptor.getInputStream(inputStreamDescriptor).window(Windows.<PageViewEvent, String, Integer>keyedTumblingWindow(PageViewEvent::getMemberId, Duration.ofSeconds(10), () -> 0, (m, c) -> c + 1, null, null).setEarlyTrigger(Triggers.repeat(Triggers.count(5))).setAccumulationMode(AccumulationMode.DISCARDING), "window1").map(m -> KV.of(m.getKey().getKey(), buildPageViewCount(m))).sendTo(appDescriptor.getOutputStream(outputStreamDescriptor));
appDescriptor.withMetricsReporterFactories(new HashMap<>());
}
Aggregations