Search in sources :

Example 6 with DoFnRunner

use of org.apache.beam.runners.core.DoFnRunner in project beam by apache.

the class StreamingKeyedWorkItemSideInputDoFnRunnerTest method createRunner.

@SuppressWarnings("unchecked")
private StreamingKeyedWorkItemSideInputDoFnRunner<String, Integer, KV<String, Integer>, IntervalWindow> createRunner(DoFnRunners.OutputManager outputManager) throws Exception {
    CoderRegistry registry = CoderRegistry.createDefault();
    Coder<String> keyCoder = StringUtf8Coder.of();
    Coder<Integer> inputCoder = BigEndianIntegerCoder.of();
    AppliedCombineFn<String, Integer, ?, Integer> combineFn = AppliedCombineFn.withInputCoder(Sum.ofIntegers(), registry, KvCoder.of(keyCoder, inputCoder));
    WindowingStrategy<Object, IntervalWindow> windowingStrategy = WindowingStrategy.of(WINDOW_FN);
    @SuppressWarnings("rawtypes") StreamingGroupAlsoByWindowViaWindowSetFn doFn = (StreamingGroupAlsoByWindowViaWindowSetFn) StreamingGroupAlsoByWindowsDoFns.create(windowingStrategy, key -> state, combineFn, keyCoder);
    DoFnRunner<KeyedWorkItem<String, Integer>, KV<String, Integer>> simpleDoFnRunner = new GroupAlsoByWindowFnRunner<>(PipelineOptionsFactory.create(), doFn.asDoFn(), mockSideInputReader, outputManager, mainOutputTag, stepContext);
    return new StreamingKeyedWorkItemSideInputDoFnRunner<String, Integer, KV<String, Integer>, IntervalWindow>(simpleDoFnRunner, keyCoder, sideInputFetcher, stepContext);
}
Also used : Arrays(java.util.Arrays) KV(org.apache.beam.sdk.values.KV) CoderRegistry(org.apache.beam.sdk.coders.CoderRegistry) KeyedWorkItems(org.apache.beam.runners.core.KeyedWorkItems) WindowedValue(org.apache.beam.sdk.util.WindowedValue) InMemoryStateInternals(org.apache.beam.runners.core.InMemoryStateInternals) Matchers(org.mockito.Matchers) Mock(org.mockito.Mock) DoFnRunner(org.apache.beam.runners.core.DoFnRunner) Duration(org.joda.time.Duration) RunWith(org.junit.runner.RunWith) Coder(org.apache.beam.sdk.coders.Coder) StateNamespaces(org.apache.beam.runners.core.StateNamespaces) TimerInternals(org.apache.beam.runners.core.TimerInternals) PipelineOptionsFactory(org.apache.beam.sdk.options.PipelineOptionsFactory) DoFnRunners(org.apache.beam.runners.core.DoFnRunners) StringUtf8Coder(org.apache.beam.sdk.coders.StringUtf8Coder) ImmutableSet(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableSet) MockitoAnnotations(org.mockito.MockitoAnnotations) ListOutputManager(org.apache.beam.runners.dataflow.worker.util.ListOutputManager) TupleTag(org.apache.beam.sdk.values.TupleTag) StateInternals(org.apache.beam.runners.core.StateInternals) TimerData(org.apache.beam.runners.core.TimerInternals.TimerData) KeyedWorkItem(org.apache.beam.runners.core.KeyedWorkItem) SideInputReader(org.apache.beam.runners.core.SideInputReader) Before(org.junit.Before) Windmill(org.apache.beam.runners.dataflow.worker.windmill.Windmill) KvCoder(org.apache.beam.sdk.coders.KvCoder) AppliedCombineFn(org.apache.beam.sdk.util.AppliedCombineFn) Timer(org.apache.beam.runners.dataflow.worker.windmill.Windmill.Timer) PaneInfo(org.apache.beam.sdk.transforms.windowing.PaneInfo) BigEndianIntegerCoder(org.apache.beam.sdk.coders.BigEndianIntegerCoder) Set(java.util.Set) Sum(org.apache.beam.sdk.transforms.Sum) FixedWindows(org.apache.beam.sdk.transforms.windowing.FixedWindows) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) JUnit4(org.junit.runners.JUnit4) List(java.util.List) BagState(org.apache.beam.sdk.state.BagState) Instant(org.joda.time.Instant) ImmutableList(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList) IntervalWindow(org.apache.beam.sdk.transforms.windowing.IntervalWindow) TimeDomain(org.apache.beam.sdk.state.TimeDomain) Assert.assertEquals(org.junit.Assert.assertEquals) ValueInEmptyWindows(org.apache.beam.runners.dataflow.worker.util.ValueInEmptyWindows) WindowingStrategy(org.apache.beam.sdk.values.WindowingStrategy) KV(org.apache.beam.sdk.values.KV) KeyedWorkItem(org.apache.beam.runners.core.KeyedWorkItem) CoderRegistry(org.apache.beam.sdk.coders.CoderRegistry) IntervalWindow(org.apache.beam.sdk.transforms.windowing.IntervalWindow)

Aggregations

DoFnRunner (org.apache.beam.runners.core.DoFnRunner)6 WindowedValue (org.apache.beam.sdk.util.WindowedValue)5 KV (org.apache.beam.sdk.values.KV)5 TupleTag (org.apache.beam.sdk.values.TupleTag)5 List (java.util.List)4 TimerInternals (org.apache.beam.runners.core.TimerInternals)4 WindowingStrategy (org.apache.beam.sdk.values.WindowingStrategy)4 Instant (org.joda.time.Instant)4 Arrays (java.util.Arrays)3 DoFnRunners (org.apache.beam.runners.core.DoFnRunners)3 StateInternals (org.apache.beam.runners.core.StateInternals)3 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 InMemoryStateInternals (org.apache.beam.runners.core.InMemoryStateInternals)2 KeyedWorkItem (org.apache.beam.runners.core.KeyedWorkItem)2 SideInputReader (org.apache.beam.runners.core.SideInputReader)2 StepContext (org.apache.beam.runners.core.StepContext)2