Search in sources :

Example 1 with CreatePCollectionView

use of org.apache.beam.sdk.transforms.View.CreatePCollectionView in project beam by apache.

the class ViewOverrideFactoryTest method replacementGetViewReturnsOriginal.

@Test
public void replacementGetViewReturnsOriginal() {
    final PCollection<Integer> ints = p.apply("CreateContents", Create.of(1, 2, 3));
    final PCollectionView<List<Integer>> view = PCollectionViews.listView(ints, WindowingStrategy.globalDefault(), ints.getCoder());
    PTransformReplacement<PCollection<Integer>, PCollectionView<List<Integer>>> replacement = factory.getReplacementTransform(AppliedPTransform.<PCollection<Integer>, PCollectionView<List<Integer>>, CreatePCollectionView<Integer, List<Integer>>>of("foo", ints.expand(), view.expand(), CreatePCollectionView.<Integer, List<Integer>>of(view), p));
    ints.apply(replacement.getTransform());
    final AtomicBoolean writeViewVisited = new AtomicBoolean();
    p.traverseTopologically(new PipelineVisitor.Defaults() {

        @Override
        public void visitPrimitiveTransform(Node node) {
            if (node.getTransform() instanceof WriteView) {
                assertThat("There should only be one WriteView primitive in the graph", writeViewVisited.getAndSet(true), is(false));
                PCollectionView replacementView = ((WriteView) node.getTransform()).getView();
                assertThat(replacementView, Matchers.<PCollectionView>theInstance(view));
                assertThat(node.getInputs().entrySet(), hasSize(1));
            }
        }
    });
    assertThat(writeViewVisited.get(), is(true));
}
Also used : WriteView(org.apache.beam.runners.direct.ViewOverrideFactory.WriteView) Node(org.apache.beam.sdk.runners.TransformHierarchy.Node) PCollection(org.apache.beam.sdk.values.PCollection) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PCollectionView(org.apache.beam.sdk.values.PCollectionView) CreatePCollectionView(org.apache.beam.sdk.transforms.View.CreatePCollectionView) PipelineVisitor(org.apache.beam.sdk.Pipeline.PipelineVisitor) List(java.util.List) Test(org.junit.Test)

Aggregations

List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 WriteView (org.apache.beam.runners.direct.ViewOverrideFactory.WriteView)1 PipelineVisitor (org.apache.beam.sdk.Pipeline.PipelineVisitor)1 Node (org.apache.beam.sdk.runners.TransformHierarchy.Node)1 CreatePCollectionView (org.apache.beam.sdk.transforms.View.CreatePCollectionView)1 PCollection (org.apache.beam.sdk.values.PCollection)1 PCollectionView (org.apache.beam.sdk.values.PCollectionView)1 Test (org.junit.Test)1