Search in sources :

Example 1 with MessageWithComponents

use of org.apache.beam.model.pipeline.v1.RunnerApi.MessageWithComponents in project beam by apache.

the class ModelCodersTest method windowedValueCoderComponentsToConstructor.

@Test
public void windowedValueCoderComponentsToConstructor() throws IOException {
    FullWindowedValueCoder<Iterable<KV<String, Integer>>> javaCoder = FullWindowedValueCoder.of(IterableCoder.of(KvCoder.of(StringUtf8Coder.of(), VarIntCoder.of())), IntervalWindowCoder.of());
    MessageWithComponents coderAndComponents = CoderTranslation.toProto(javaCoder);
    WindowedValueCoderComponents windowedValueCoderComponents = ModelCoders.getWindowedValueCoderComponents(coderAndComponents.getCoder());
    Coder windowedCoder = ModelCoders.windowedValueCoder(windowedValueCoderComponents.elementCoderId(), windowedValueCoderComponents.windowCoderId());
    assertThat(windowedCoder, equalTo(coderAndComponents.getCoder()));
}
Also used : WindowedValueCoderComponents(org.apache.beam.runners.core.construction.ModelCoders.WindowedValueCoderComponents) KvCoder(org.apache.beam.sdk.coders.KvCoder) Coder(org.apache.beam.model.pipeline.v1.RunnerApi.Coder) IterableCoder(org.apache.beam.sdk.coders.IterableCoder) FullWindowedValueCoder(org.apache.beam.sdk.util.WindowedValue.FullWindowedValueCoder) VarLongCoder(org.apache.beam.sdk.coders.VarLongCoder) StringUtf8Coder(org.apache.beam.sdk.coders.StringUtf8Coder) ByteArrayCoder(org.apache.beam.sdk.coders.ByteArrayCoder) VarIntCoder(org.apache.beam.sdk.coders.VarIntCoder) IntervalWindowCoder(org.apache.beam.sdk.transforms.windowing.IntervalWindow.IntervalWindowCoder) LengthPrefixCoder(org.apache.beam.sdk.coders.LengthPrefixCoder) MessageWithComponents(org.apache.beam.model.pipeline.v1.RunnerApi.MessageWithComponents) Test(org.junit.Test)

Example 2 with MessageWithComponents

use of org.apache.beam.model.pipeline.v1.RunnerApi.MessageWithComponents in project beam by apache.

the class ModelCodersTest method kvCoderComponentsToConstructor.

@Test
public void kvCoderComponentsToConstructor() throws IOException {
    KvCoder<byte[], Iterable<Long>> javaCoder = KvCoder.of(ByteArrayCoder.of(), IterableCoder.of(LengthPrefixCoder.of(VarLongCoder.of())));
    MessageWithComponents coderAndComponents = CoderTranslation.toProto(javaCoder);
    KvCoderComponents kvCoderComponents = ModelCoders.getKvCoderComponents(coderAndComponents.getCoder());
    Coder kvCoder = ModelCoders.kvCoder(kvCoderComponents.keyCoderId(), kvCoderComponents.valueCoderId());
    assertThat(kvCoder, equalTo(coderAndComponents.getCoder()));
}
Also used : KvCoder(org.apache.beam.sdk.coders.KvCoder) Coder(org.apache.beam.model.pipeline.v1.RunnerApi.Coder) IterableCoder(org.apache.beam.sdk.coders.IterableCoder) FullWindowedValueCoder(org.apache.beam.sdk.util.WindowedValue.FullWindowedValueCoder) VarLongCoder(org.apache.beam.sdk.coders.VarLongCoder) StringUtf8Coder(org.apache.beam.sdk.coders.StringUtf8Coder) ByteArrayCoder(org.apache.beam.sdk.coders.ByteArrayCoder) VarIntCoder(org.apache.beam.sdk.coders.VarIntCoder) IntervalWindowCoder(org.apache.beam.sdk.transforms.windowing.IntervalWindow.IntervalWindowCoder) LengthPrefixCoder(org.apache.beam.sdk.coders.LengthPrefixCoder) MessageWithComponents(org.apache.beam.model.pipeline.v1.RunnerApi.MessageWithComponents) KvCoderComponents(org.apache.beam.runners.core.construction.ModelCoders.KvCoderComponents) Test(org.junit.Test)

Example 3 with MessageWithComponents

use of org.apache.beam.model.pipeline.v1.RunnerApi.MessageWithComponents in project beam by apache.

the class ProtoOverrides method updateTransform.

/**
 * Update all composites present in the {@code originalPipeline} with an URN equal to the provided
 * {@code urn} using the provided {@link TransformReplacement}.
 */
public static Pipeline updateTransform(String urn, Pipeline originalPipeline, TransformReplacement compositeBuilder) {
    Components.Builder resultComponents = originalPipeline.getComponents().toBuilder();
    for (Map.Entry<String, PTransform> pt : originalPipeline.getComponents().getTransformsMap().entrySet()) {
        if (pt.getValue().getSpec() != null && urn.equals(pt.getValue().getSpec().getUrn())) {
            MessageWithComponents updated = compositeBuilder.getReplacement(pt.getKey(), originalPipeline.getComponents());
            if (updated == null) {
                continue;
            }
            checkArgument(updated.getPtransform().getOutputsMap().equals(pt.getValue().getOutputsMap()), "A %s must produce all of the outputs of the original %s", TransformReplacement.class.getSimpleName(), PTransform.class.getSimpleName());
            removeSubtransforms(pt.getValue(), resultComponents);
            resultComponents.mergeFrom(updated.getComponents()).putTransforms(pt.getKey(), updated.getPtransform());
        }
    }
    return originalPipeline.toBuilder().setComponents(resultComponents).build();
}
Also used : Components(org.apache.beam.model.pipeline.v1.RunnerApi.Components) MessageWithComponents(org.apache.beam.model.pipeline.v1.RunnerApi.MessageWithComponents) MessageWithComponents(org.apache.beam.model.pipeline.v1.RunnerApi.MessageWithComponents) Map(java.util.Map) PTransform(org.apache.beam.model.pipeline.v1.RunnerApi.PTransform)

Aggregations

MessageWithComponents (org.apache.beam.model.pipeline.v1.RunnerApi.MessageWithComponents)3 Coder (org.apache.beam.model.pipeline.v1.RunnerApi.Coder)2 ByteArrayCoder (org.apache.beam.sdk.coders.ByteArrayCoder)2 IterableCoder (org.apache.beam.sdk.coders.IterableCoder)2 KvCoder (org.apache.beam.sdk.coders.KvCoder)2 LengthPrefixCoder (org.apache.beam.sdk.coders.LengthPrefixCoder)2 StringUtf8Coder (org.apache.beam.sdk.coders.StringUtf8Coder)2 VarIntCoder (org.apache.beam.sdk.coders.VarIntCoder)2 VarLongCoder (org.apache.beam.sdk.coders.VarLongCoder)2 IntervalWindowCoder (org.apache.beam.sdk.transforms.windowing.IntervalWindow.IntervalWindowCoder)2 FullWindowedValueCoder (org.apache.beam.sdk.util.WindowedValue.FullWindowedValueCoder)2 Test (org.junit.Test)2 Map (java.util.Map)1 Components (org.apache.beam.model.pipeline.v1.RunnerApi.Components)1 PTransform (org.apache.beam.model.pipeline.v1.RunnerApi.PTransform)1 KvCoderComponents (org.apache.beam.runners.core.construction.ModelCoders.KvCoderComponents)1 WindowedValueCoderComponents (org.apache.beam.runners.core.construction.ModelCoders.WindowedValueCoderComponents)1