Search in sources :

Example 11 with PTransformMatcher

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

the class PTransformMatchersTest method createViewWithViewFnDifferentViewFn.

@Test
public void createViewWithViewFnDifferentViewFn() {
    PCollection<Integer> input = p.apply(Create.of(1));
    PCollectionView<Iterable<Integer>> view = PCollectionViews.iterableView(input, input.getWindowingStrategy(), input.getCoder());
    ViewFn<Iterable<WindowedValue<?>>, Iterable<Integer>> viewFn = new ViewFn<Iterable<WindowedValue<?>>, Iterable<Integer>>() {

        @Override
        public Materialization<Iterable<WindowedValue<?>>> getMaterialization() {
            @SuppressWarnings({ "rawtypes", "unchecked" }) Materialization<Iterable<WindowedValue<?>>> materialization = (Materialization) Materializations.iterable();
            return materialization;
        }

        @Override
        public Iterable<Integer> apply(Iterable<WindowedValue<?>> contents) {
            return Collections.emptyList();
        }
    };
    CreatePCollectionView<?, ?> createView = CreatePCollectionView.of(view);
    PTransformMatcher matcher = PTransformMatchers.createViewWithViewFn(viewFn.getClass());
    assertThat(matcher.matches(getAppliedTransform(createView)), is(false));
}
Also used : Materialization(org.apache.beam.sdk.transforms.Materialization) PTransformMatcher(org.apache.beam.sdk.runners.PTransformMatcher) ViewFn(org.apache.beam.sdk.transforms.ViewFn) WindowedValue(org.apache.beam.sdk.util.WindowedValue) Test(org.junit.Test)

Example 12 with PTransformMatcher

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

the class PTransformMatchersTest method classEqualToDoesNotMatchUnrelatedClass.

@Test
public void classEqualToDoesNotMatchUnrelatedClass() {
    PTransformMatcher matcher = PTransformMatchers.classEqualTo(ParDo.SingleOutput.class);
    AppliedPTransform<?, ?, ?> application = getAppliedTransform(Window.<KV<String, Integer>>into(new GlobalWindows()));
    assertThat(matcher.matches(application), is(false));
}
Also used : PTransformMatcher(org.apache.beam.sdk.runners.PTransformMatcher) GlobalWindows(org.apache.beam.sdk.transforms.windowing.GlobalWindows) ParDo(org.apache.beam.sdk.transforms.ParDo) Test(org.junit.Test)

Example 13 with PTransformMatcher

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

the class PTransformMatchersTest method createViewWithViewFnNotCreatePCollectionView.

@Test
public void createViewWithViewFnNotCreatePCollectionView() {
    PCollection<Integer> input = p.apply(Create.of(1));
    PCollectionView<Iterable<Integer>> view = PCollectionViews.iterableView(input, input.getWindowingStrategy(), input.getCoder());
    PTransformMatcher matcher = PTransformMatchers.createViewWithViewFn(view.getViewFn().getClass());
    assertThat(matcher.matches(getAppliedTransform(View.asIterable())), is(false));
}
Also used : PTransformMatcher(org.apache.beam.sdk.runners.PTransformMatcher) Test(org.junit.Test)

Example 14 with PTransformMatcher

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

the class PTransformMatchersTest method createViewWithViewFn.

@Test
public void createViewWithViewFn() {
    PCollection<Integer> input = p.apply(Create.of(1));
    PCollectionView<Iterable<Integer>> view = PCollectionViews.iterableView(input, input.getWindowingStrategy(), input.getCoder());
    ViewFn<Iterable<WindowedValue<?>>, Iterable<Integer>> viewFn = view.getViewFn();
    CreatePCollectionView<?, ?> createView = CreatePCollectionView.of(view);
    PTransformMatcher matcher = PTransformMatchers.createViewWithViewFn(viewFn.getClass());
    assertThat(matcher.matches(getAppliedTransform(createView)), is(true));
}
Also used : PTransformMatcher(org.apache.beam.sdk.runners.PTransformMatcher) Test(org.junit.Test)

Example 15 with PTransformMatcher

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

the class PTransformMatchersTest method parDoWithFnTypeNotParDo.

@Test
public void parDoWithFnTypeNotParDo() {
    AppliedPTransform<?, ?, ?> notParDo = getAppliedTransform(Create.empty(VoidCoder.of()));
    PTransformMatcher matcher = PTransformMatchers.parDoWithFnType(doFnWithState.getClass());
    assertThat(matcher.matches(notParDo), is(false));
}
Also used : PTransformMatcher(org.apache.beam.sdk.runners.PTransformMatcher) Test(org.junit.Test)

Aggregations

PTransformMatcher (org.apache.beam.sdk.runners.PTransformMatcher)15 Test (org.junit.Test)11 AppliedPTransform (org.apache.beam.sdk.runners.AppliedPTransform)6 DoFnSignature (org.apache.beam.sdk.transforms.reflect.DoFnSignature)4 DoFn (org.apache.beam.sdk.transforms.DoFn)3 GenerateSequence (org.apache.beam.sdk.io.GenerateSequence)2 PTransformOverride (org.apache.beam.sdk.runners.PTransformOverride)2 Create (org.apache.beam.sdk.transforms.Create)2 PTransform (org.apache.beam.sdk.transforms.PTransform)2 ParDo (org.apache.beam.sdk.transforms.ParDo)2 TupleTag (org.apache.beam.sdk.values.TupleTag)2 PipelineVisitor (org.apache.beam.sdk.Pipeline.PipelineVisitor)1 Node (org.apache.beam.sdk.runners.TransformHierarchy.Node)1 Materialization (org.apache.beam.sdk.transforms.Materialization)1 ViewFn (org.apache.beam.sdk.transforms.ViewFn)1 GlobalWindows (org.apache.beam.sdk.transforms.windowing.GlobalWindows)1 WindowedValue (org.apache.beam.sdk.util.WindowedValue)1 KV (org.apache.beam.sdk.values.KV)1 PCollection (org.apache.beam.sdk.values.PCollection)1