Search in sources :

Example 1 with PTransformMatcher

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

the class PTransformMatchersTest method classEqualToMatchesSameClass.

@Test
public void classEqualToMatchesSameClass() {
    PTransformMatcher matcher = PTransformMatchers.classEqualTo(ParDo.SingleOutput.class);
    AppliedPTransform<?, ?, ?> application = getAppliedTransform(ParDo.of(new DoFn<KV<String, Integer>, Integer>() {

        @ProcessElement
        public void doStuff(ProcessContext ctxt) {
        }
    }));
    assertThat(matcher.matches(application), is(true));
}
Also used : DoFn(org.apache.beam.sdk.transforms.DoFn) PTransformMatcher(org.apache.beam.sdk.runners.PTransformMatcher) ParDo(org.apache.beam.sdk.transforms.ParDo) Test(org.junit.Test)

Example 2 with PTransformMatcher

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

the class PTransformMatchersTest method parDoWithFnTypeWithNoMatch.

@Test
public void parDoWithFnTypeWithNoMatch() {
    DoFn<Object, Object> fn = new DoFn<Object, Object>() {

        @ProcessElement
        public void process(ProcessContext ctxt) {
        }
    };
    AppliedPTransform<?, ?, ?> parDoSingle = getAppliedTransform(ParDo.of(fn));
    AppliedPTransform<?, ?, ?> parDoMulti = getAppliedTransform(ParDo.of(fn).withOutputTags(new TupleTag<Object>(), TupleTagList.empty()));
    PTransformMatcher matcher = PTransformMatchers.parDoWithFnType(doFnWithState.getClass());
    assertThat(matcher.matches(parDoSingle), is(false));
    assertThat(matcher.matches(parDoMulti), is(false));
}
Also used : DoFn(org.apache.beam.sdk.transforms.DoFn) PTransformMatcher(org.apache.beam.sdk.runners.PTransformMatcher) TupleTag(org.apache.beam.sdk.values.TupleTag) Test(org.junit.Test)

Example 3 with PTransformMatcher

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

the class PTransformMatchersTest method classEqualToDoesNotMatchSubclass.

@Test
public void classEqualToDoesNotMatchSubclass() {
    class MyPTransform extends PTransform<PCollection<KV<String, Integer>>, PCollection<Integer>> {

        @Override
        public PCollection<Integer> expand(PCollection<KV<String, Integer>> input) {
            return PCollection.createPrimitiveOutputInternal(input.getPipeline(), input.getWindowingStrategy(), input.isBounded());
        }
    }
    PTransformMatcher matcher = PTransformMatchers.classEqualTo(MyPTransform.class);
    MyPTransform subclass = new MyPTransform() {
    };
    assertThat(subclass.getClass(), not(Matchers.<Class<?>>equalTo(MyPTransform.class)));
    assertThat(subclass, instanceOf(MyPTransform.class));
    AppliedPTransform<?, ?, ?> application = getAppliedTransform(subclass);
    assertThat(matcher.matches(application), is(false));
}
Also used : PCollection(org.apache.beam.sdk.values.PCollection) PTransformMatcher(org.apache.beam.sdk.runners.PTransformMatcher) KV(org.apache.beam.sdk.values.KV) PTransform(org.apache.beam.sdk.transforms.PTransform) AppliedPTransform(org.apache.beam.sdk.runners.AppliedPTransform) Test(org.junit.Test)

Example 4 with PTransformMatcher

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

the class PTransformMatchers method splittableParDoSingle.

/**
   * A {@link PTransformMatcher} that matches a {@link ParDo.SingleOutput} containing a {@link DoFn}
   * that is splittable, as signified by {@link ProcessElementMethod#isSplittable()}.
   */
public static PTransformMatcher splittableParDoSingle() {
    return new PTransformMatcher() {

        @Override
        public boolean matches(AppliedPTransform<?, ?, ?> application) {
            PTransform<?, ?> transform = application.getTransform();
            if (transform instanceof ParDo.SingleOutput) {
                DoFn<?, ?> fn = ((ParDo.SingleOutput<?, ?>) transform).getFn();
                DoFnSignature signature = DoFnSignatures.signatureForDoFn(fn);
                return signature.processElement().isSplittable();
            }
            return false;
        }

        @Override
        public String toString() {
            return MoreObjects.toStringHelper("SplittableParDoSingleMatcher").toString();
        }
    };
}
Also used : PTransformMatcher(org.apache.beam.sdk.runners.PTransformMatcher) AppliedPTransform(org.apache.beam.sdk.runners.AppliedPTransform) DoFnSignature(org.apache.beam.sdk.transforms.reflect.DoFnSignature)

Example 5 with PTransformMatcher

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

the class PTransformMatchers method splittableParDoMulti.

/**
   * A {@link PTransformMatcher} that matches a {@link ParDo.MultiOutput} containing a {@link DoFn}
   * that is splittable, as signified by {@link ProcessElementMethod#isSplittable()}.
   */
public static PTransformMatcher splittableParDoMulti() {
    return new PTransformMatcher() {

        @Override
        public boolean matches(AppliedPTransform<?, ?, ?> application) {
            PTransform<?, ?> transform = application.getTransform();
            if (transform instanceof ParDo.MultiOutput) {
                DoFn<?, ?> fn = ((ParDo.MultiOutput<?, ?>) transform).getFn();
                DoFnSignature signature = DoFnSignatures.signatureForDoFn(fn);
                return signature.processElement().isSplittable();
            }
            return false;
        }

        @Override
        public String toString() {
            return MoreObjects.toStringHelper("SplittableParDoMultiMatcher").toString();
        }
    };
}
Also used : PTransformMatcher(org.apache.beam.sdk.runners.PTransformMatcher) AppliedPTransform(org.apache.beam.sdk.runners.AppliedPTransform) DoFnSignature(org.apache.beam.sdk.transforms.reflect.DoFnSignature)

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