use of org.apache.beam.sdk.values.TupleTag in project beam by apache.
the class PTransformMatchersTest method emptyFlattenWithNonFlatten.
@Test
public void emptyFlattenWithNonFlatten() {
AppliedPTransform application = AppliedPTransform.<PCollection<Iterable<Integer>>, PCollection<Integer>, Flatten.Iterables<Integer>>of("EmptyFlatten", Collections.emptyMap(), Collections.singletonMap(new TupleTag<Integer>(), PCollection.createPrimitiveOutputInternal(p, WindowingStrategy.globalDefault(), IsBounded.BOUNDED, VarIntCoder.of())), /* This isn't actually possible to construct, but for the sake of example */
Flatten.iterables(), ResourceHints.create(), p);
assertThat(PTransformMatchers.emptyFlatten().matches(application), is(false));
}
use of org.apache.beam.sdk.values.TupleTag 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<>(), TupleTagList.empty()));
PTransformMatcher matcher = PTransformMatchers.parDoWithFnType(doFnWithState.getClass());
assertThat(matcher.matches(parDoSingle), is(false));
assertThat(matcher.matches(parDoMulti), is(false));
}
use of org.apache.beam.sdk.values.TupleTag in project beam by apache.
the class PTransformMatchersTest method flattenWithDuplicateInputsNonFlatten.
@Test
public void flattenWithDuplicateInputsNonFlatten() {
AppliedPTransform application = AppliedPTransform.<PCollection<Iterable<Integer>>, PCollection<Integer>, Flatten.Iterables<Integer>>of("EmptyFlatten", Collections.emptyMap(), Collections.singletonMap(new TupleTag<Integer>(), PCollection.createPrimitiveOutputInternal(p, WindowingStrategy.globalDefault(), IsBounded.BOUNDED, VarIntCoder.of())), /* This isn't actually possible to construct, but for the sake of example */
Flatten.iterables(), ResourceHints.create(), p);
assertThat(PTransformMatchers.flattenWithDuplicateInputs().matches(application), is(false));
}
use of org.apache.beam.sdk.values.TupleTag in project beam by apache.
the class PTransformTranslationTest method multiMultiParDo.
private static AppliedPTransform<?, ?, ?> multiMultiParDo(Pipeline pipeline) {
PCollectionView<String> view = pipeline.apply(Create.of("foo")).apply(View.asSingleton());
PCollection<Long> input = pipeline.apply(GenerateSequence.from(0));
ParDo.MultiOutput<Long, KV<Long, String>> parDo = ParDo.of(new TestDoFn()).withSideInputs(view).withOutputTags(new TupleTag<KV<Long, String>>() {
}, TupleTagList.of(new TupleTag<KV<String, Long>>() {
}));
PCollectionTuple output = input.apply(parDo);
Map<TupleTag<?>, PCollection<?>> inputs = new HashMap<>();
inputs.putAll(PValues.fullyExpand(parDo.getAdditionalInputs()));
inputs.putAll(PValues.expandInput(input));
return AppliedPTransform.<PCollection<Long>, PCollectionTuple, ParDo.MultiOutput<Long, KV<Long, String>>>of("MultiParDoInAndOut", inputs, PValues.expandOutput(output), parDo, ResourceHints.create(), pipeline);
}
use of org.apache.beam.sdk.values.TupleTag in project beam by apache.
the class EnvironmentsTest method getEnvironmentPTransform.
@Test
public void getEnvironmentPTransform() throws IOException {
Pipeline p = Pipeline.create();
SdkComponents components = SdkComponents.create();
Environment env = Environments.createDockerEnvironment("java");
components.registerEnvironment(env);
ParDoPayload payload = ParDoTranslation.translateParDo(ParDo.of(new DoFn<String, String>() {
@ProcessElement
public void process(ProcessContext ctxt) {
}
}).withOutputTags(new TupleTag<>(), TupleTagList.empty()), PCollection.createPrimitiveOutputInternal(p, WindowingStrategy.globalDefault(), IsBounded.BOUNDED, StringUtf8Coder.of()), DoFnSchemaInformation.create(), Pipeline.create(), components);
RehydratedComponents rehydratedComponents = RehydratedComponents.forComponents(components.toComponents());
PTransform ptransform = PTransform.newBuilder().setSpec(FunctionSpec.newBuilder().setUrn(PTransformTranslation.PAR_DO_TRANSFORM_URN).setPayload(payload.toByteString()).build()).setEnvironmentId(components.getOnlyEnvironmentId()).build();
Environment env1 = Environments.getEnvironment(ptransform, rehydratedComponents).get();
assertThat(env1, equalTo(components.toComponents().getEnvironmentsOrThrow(ptransform.getEnvironmentId())));
}
Aggregations