Search in sources :

Example 21 with AppliedPTransform

use of org.apache.beam.sdk.runners.AppliedPTransform in project beam by apache.

the class WatermarkManagerTest method getWatermarkMultiIdenticalInput.

/**
   * Demonstrates that getWatermark for a transform that takes multiple inputs is held to the
   * minimum watermark across all of its inputs.
   */
@Test
public void getWatermarkMultiIdenticalInput() {
    PCollection<Integer> created = p.apply(Create.of(1, 2, 3));
    PCollection<Integer> multiConsumer = PCollectionList.of(created).and(created).apply(Flatten.<Integer>pCollections());
    DirectGraphVisitor graphVisitor = new DirectGraphVisitor();
    p.traverseTopologically(graphVisitor);
    DirectGraph graph = graphVisitor.getGraph();
    AppliedPTransform<?, ?, ?> theFlatten = graph.getProducer(multiConsumer);
    WatermarkManager tstMgr = WatermarkManager.create(clock, graph);
    CommittedBundle<Void> root = bundleFactory.<Void>createRootBundle().add(WindowedValue.<Void>valueInGlobalWindow(null)).commit(clock.now());
    CommittedBundle<Integer> createBundle = bundleFactory.createBundle(created).add(WindowedValue.timestampedValueInGlobalWindow(1, new Instant(33536))).commit(clock.now());
    Map<AppliedPTransform<?, ?, ?>, Collection<CommittedBundle<?>>> initialInputs = ImmutableMap.<AppliedPTransform<?, ?, ?>, Collection<CommittedBundle<?>>>builder().put(graph.getProducer(created), Collections.<CommittedBundle<?>>singleton(root)).build();
    tstMgr.initialize(initialInputs);
    tstMgr.updateWatermarks(root, TimerUpdate.empty(), CommittedResult.create(StepTransformResult.withoutHold(graph.getProducer(created)).build(), root.withElements(Collections.<WindowedValue<Void>>emptyList()), Collections.singleton(createBundle), EnumSet.allOf(OutputType.class)), BoundedWindow.TIMESTAMP_MAX_VALUE);
    tstMgr.refreshAll();
    TransformWatermarks flattenWms = tstMgr.getWatermarks(theFlatten);
    assertThat(flattenWms.getInputWatermark(), equalTo(new Instant(33536)));
    tstMgr.updateWatermarks(createBundle, TimerUpdate.empty(), CommittedResult.create(StepTransformResult.withoutHold(theFlatten).build(), createBundle.withElements(Collections.<WindowedValue<Integer>>emptyList()), Collections.<CommittedBundle<?>>emptyList(), EnumSet.allOf(OutputType.class)), BoundedWindow.TIMESTAMP_MAX_VALUE);
    tstMgr.refreshAll();
    assertThat(flattenWms.getInputWatermark(), equalTo(new Instant(33536)));
    tstMgr.updateWatermarks(createBundle, TimerUpdate.empty(), CommittedResult.create(StepTransformResult.withoutHold(theFlatten).build(), createBundle.withElements(Collections.<WindowedValue<Integer>>emptyList()), Collections.<CommittedBundle<?>>emptyList(), EnumSet.allOf(OutputType.class)), BoundedWindow.TIMESTAMP_MAX_VALUE);
    tstMgr.refreshAll();
    assertThat(flattenWms.getInputWatermark(), equalTo(BoundedWindow.TIMESTAMP_MAX_VALUE));
}
Also used : TransformWatermarks(org.apache.beam.runners.direct.WatermarkManager.TransformWatermarks) ReadableInstant(org.joda.time.ReadableInstant) Instant(org.joda.time.Instant) AppliedPTransform(org.apache.beam.sdk.runners.AppliedPTransform) Collection(java.util.Collection) PCollection(org.apache.beam.sdk.values.PCollection) Test(org.junit.Test)

Aggregations

AppliedPTransform (org.apache.beam.sdk.runners.AppliedPTransform)21 Test (org.junit.Test)13 PCollection (org.apache.beam.sdk.values.PCollection)12 TupleTag (org.apache.beam.sdk.values.TupleTag)9 PTransformMatcher (org.apache.beam.sdk.runners.PTransformMatcher)6 DoFnSignature (org.apache.beam.sdk.transforms.reflect.DoFnSignature)4 PCollectionList (org.apache.beam.sdk.values.PCollectionList)4 PipelineVisitor (org.apache.beam.sdk.Pipeline.PipelineVisitor)3 Node (org.apache.beam.sdk.runners.TransformHierarchy.Node)3 PTransform (org.apache.beam.sdk.transforms.PTransform)3 KV (org.apache.beam.sdk.values.KV)3 PValue (org.apache.beam.sdk.values.PValue)3 Instant (org.joda.time.Instant)3 ArrayList (java.util.ArrayList)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 KeyedWorkItem (org.apache.beam.runners.core.KeyedWorkItem)2 StatefulParDo (org.apache.beam.runners.direct.ParDoMultiOverrideFactory.StatefulParDo)2 ValueState (org.apache.beam.sdk.state.ValueState)2 BoundedWindow (org.apache.beam.sdk.transforms.windowing.BoundedWindow)2 IntervalWindow (org.apache.beam.sdk.transforms.windowing.IntervalWindow)2