Search in sources :

Example 1 with AppliedPTransform

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

the class PTransformMatchersTest method emptyFlattenWithNonEmptyFlatten.

@Test
public void emptyFlattenWithNonEmptyFlatten() {
    AppliedPTransform application = AppliedPTransform.<PCollectionList<Object>, PCollection<Object>, Flatten.PCollections<Object>>of("Flatten", Collections.<TupleTag<?>, PValue>singletonMap(new TupleTag<Object>(), PCollection.createPrimitiveOutputInternal(p, WindowingStrategy.globalDefault(), IsBounded.BOUNDED)), Collections.<TupleTag<?>, PValue>singletonMap(new TupleTag<Object>(), PCollection.createPrimitiveOutputInternal(p, WindowingStrategy.globalDefault(), IsBounded.BOUNDED)), Flatten.pCollections(), p);
    assertThat(PTransformMatchers.emptyFlatten().matches(application), is(false));
}
Also used : PCollectionList(org.apache.beam.sdk.values.PCollectionList) PCollection(org.apache.beam.sdk.values.PCollection) AppliedPTransform(org.apache.beam.sdk.runners.AppliedPTransform) TupleTag(org.apache.beam.sdk.values.TupleTag) Test(org.junit.Test)

Example 2 with AppliedPTransform

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

the class PTransformTranslationTest method convert.

private RunnerApi.PTransform convert(ToAndFromProtoSpec spec, SdkComponents components) throws IOException {
    List<AppliedPTransform<?, ?, ?>> childTransforms = new ArrayList<>();
    for (ToAndFromProtoSpec child : spec.getChildren()) {
        childTransforms.add(child.getTransform());
        System.out.println("Converting child " + child);
        convert(child, components);
        // Sanity call
        components.getExistingPTransformId(child.getTransform());
    }
    PTransform convert = PTransformTranslation.toProto(spec.getTransform(), childTransforms, components);
    // Make sure the converted transform is registered. Convert it independently, but if this is a
    // child spec, the child must be in the components.
    components.registerPTransform(spec.getTransform(), childTransforms);
    return convert;
}
Also used : AppliedPTransform(org.apache.beam.sdk.runners.AppliedPTransform) ArrayList(java.util.ArrayList) AppliedPTransform(org.apache.beam.sdk.runners.AppliedPTransform) PTransform(org.apache.beam.sdk.common.runner.v1.RunnerApi.PTransform)

Example 3 with AppliedPTransform

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

the class PTransformMatchersTest method emptyFlattenWithNonFlatten.

@Test
public void emptyFlattenWithNonFlatten() {
    AppliedPTransform application = AppliedPTransform.<PCollection<Iterable<Object>>, PCollection<Object>, Flatten.Iterables<Object>>of("EmptyFlatten", Collections.<TupleTag<?>, PValue>emptyMap(), Collections.<TupleTag<?>, PValue>singletonMap(new TupleTag<Object>(), PCollection.createPrimitiveOutputInternal(p, WindowingStrategy.globalDefault(), IsBounded.BOUNDED)), Flatten.iterables(), /* This isn't actually possible to construct,
                                 * but for the sake of example */
    p);
    assertThat(PTransformMatchers.emptyFlatten().matches(application), is(false));
}
Also used : PCollection(org.apache.beam.sdk.values.PCollection) AppliedPTransform(org.apache.beam.sdk.runners.AppliedPTransform) TupleTag(org.apache.beam.sdk.values.TupleTag) Test(org.junit.Test)

Example 4 with AppliedPTransform

use of org.apache.beam.sdk.runners.AppliedPTransform 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 5 with AppliedPTransform

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

the class PTransformMatchersTest method flattenWithDuplicateInputsNonFlatten.

@Test
public void flattenWithDuplicateInputsNonFlatten() {
    AppliedPTransform application = AppliedPTransform.<PCollection<Iterable<Object>>, PCollection<Object>, Flatten.Iterables<Object>>of("EmptyFlatten", Collections.<TupleTag<?>, PValue>emptyMap(), Collections.<TupleTag<?>, PValue>singletonMap(new TupleTag<Object>(), PCollection.createPrimitiveOutputInternal(p, WindowingStrategy.globalDefault(), IsBounded.BOUNDED)), Flatten.iterables(), /* This isn't actually possible to construct,
                                 * but for the sake of example */
    p);
    assertThat(PTransformMatchers.flattenWithDuplicateInputs().matches(application), is(false));
}
Also used : PCollection(org.apache.beam.sdk.values.PCollection) AppliedPTransform(org.apache.beam.sdk.runners.AppliedPTransform) TupleTag(org.apache.beam.sdk.values.TupleTag) 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