Search in sources :

Example 6 with CombinePayload

use of org.apache.beam.sdk.common.runner.v1.RunnerApi.CombinePayload in project beam by apache.

the class CombineTranslationTest method testToFromProto.

@Test
public void testToFromProto() throws Exception {
    PCollection<Integer> input = pipeline.apply(Create.of(1, 2, 3));
    input.apply(Combine.globally(combineFn));
    final AtomicReference<AppliedPTransform<?, ?, Combine.PerKey<?, ?, ?>>> combine = new AtomicReference<>();
    pipeline.traverseTopologically(new PipelineVisitor.Defaults() {

        @Override
        public void leaveCompositeTransform(Node node) {
            if (node.getTransform() instanceof Combine.PerKey) {
                checkState(combine.get() == null);
                combine.set((AppliedPTransform) node.toAppliedPTransform(getPipeline()));
            }
        }
    });
    checkState(combine.get() != null);
    SdkComponents sdkComponents = SdkComponents.create();
    CombinePayload combineProto = CombineTranslation.toProto(combine.get(), sdkComponents);
    RunnerApi.Components componentsProto = sdkComponents.toComponents();
    assertEquals(combineFn.getAccumulatorCoder(pipeline.getCoderRegistry(), input.getCoder()), CombineTranslation.getAccumulatorCoder(combineProto, componentsProto));
    assertEquals(combineFn, CombineTranslation.getCombineFn(combineProto));
}
Also used : Combine(org.apache.beam.sdk.transforms.Combine) Node(org.apache.beam.sdk.runners.TransformHierarchy.Node) AtomicReference(java.util.concurrent.atomic.AtomicReference) RunnerApi(org.apache.beam.sdk.common.runner.v1.RunnerApi) CombinePayload(org.apache.beam.sdk.common.runner.v1.RunnerApi.CombinePayload) AppliedPTransform(org.apache.beam.sdk.runners.AppliedPTransform) PipelineVisitor(org.apache.beam.sdk.Pipeline.PipelineVisitor) Test(org.junit.Test)

Aggregations

CombinePayload (org.apache.beam.model.pipeline.v1.RunnerApi.CombinePayload)5 CombineFn (org.apache.beam.sdk.transforms.Combine.CombineFn)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 PipelineVisitor (org.apache.beam.sdk.Pipeline.PipelineVisitor)1 RunnerApi (org.apache.beam.sdk.common.runner.v1.RunnerApi)1 CombinePayload (org.apache.beam.sdk.common.runner.v1.RunnerApi.CombinePayload)1 AppliedPTransform (org.apache.beam.sdk.runners.AppliedPTransform)1 Node (org.apache.beam.sdk.runners.TransformHierarchy.Node)1 Combine (org.apache.beam.sdk.transforms.Combine)1 Test (org.junit.Test)1