Search in sources :

Example 6 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 7 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)

Example 8 with PTransformMatcher

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

the class PTransformMatchers method stateOrTimerParDoSingle.

/**
   * A {@link PTransformMatcher} that matches a {@link ParDo.SingleOutput} containing a {@link DoFn}
   * that uses state or timers, as specified by {@link DoFnSignature#usesState()} and {@link
   * DoFnSignature#usesTimers()}.
   */
public static PTransformMatcher stateOrTimerParDoSingle() {
    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.usesState() || signature.usesTimers();
            }
            return false;
        }

        @Override
        public String toString() {
            return MoreObjects.toStringHelper("StateOrTimerParDoSingleMatcher").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 9 with PTransformMatcher

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

the class PTransformMatchers method stateOrTimerParDoMulti.

/**
   * A {@link PTransformMatcher} that matches a {@link ParDo.MultiOutput} containing a {@link DoFn}
   * that uses state or timers, as specified by {@link DoFnSignature#usesState()} and
   * {@link DoFnSignature#usesTimers()}.
   */
public static PTransformMatcher stateOrTimerParDoMulti() {
    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.usesState() || signature.usesTimers();
            }
            return false;
        }

        @Override
        public String toString() {
            return MoreObjects.toStringHelper("StateOrTimerParDoMultiMatcher").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 10 with PTransformMatcher

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

the class PTransformMatchersTest method parDoWithFnTypeWithMatchingType.

@Test
public void parDoWithFnTypeWithMatchingType() {
    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(fn.getClass());
    assertThat(matcher.matches(parDoSingle), is(true));
    assertThat(matcher.matches(parDoMulti), is(true));
}
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)

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