use of org.apache.beam.sdk.transforms.DoFn in project beam by apache.
the class BatchStatefulParDoOverridesTest method testSingleOutputOverrideNonCrashing.
@Test
public void testSingleOutputOverrideNonCrashing() throws Exception {
DataflowPipelineOptions options = buildPipelineOptions();
options.setRunner(DataflowRunner.class);
Pipeline pipeline = Pipeline.create(options);
DummyStatefulDoFn fn = new DummyStatefulDoFn();
pipeline.apply(Create.of(KV.of(1, 2))).apply(ParDo.of(fn));
DataflowRunner runner = DataflowRunner.fromOptions(options);
runner.replaceV1Transforms(pipeline);
assertThat(findBatchStatefulDoFn(pipeline), equalTo((DoFn) fn));
}
use of org.apache.beam.sdk.transforms.DoFn in project beam by apache.
the class BatchStatefulParDoOverridesTest method testMultiOutputOverrideNonCrashing.
@Test
public void testMultiOutputOverrideNonCrashing() throws Exception {
DataflowPipelineOptions options = buildPipelineOptions();
options.setRunner(DataflowRunner.class);
Pipeline pipeline = Pipeline.create(options);
TupleTag<Integer> mainOutputTag = new TupleTag<Integer>() {
};
TupleTag<Integer> sideOutputTag = new TupleTag<Integer>() {
};
DummyStatefulDoFn fn = new DummyStatefulDoFn();
pipeline.apply(Create.of(KV.of(1, 2))).apply(ParDo.of(fn).withOutputTags(mainOutputTag, TupleTagList.of(sideOutputTag)));
DataflowRunner runner = DataflowRunner.fromOptions(options);
runner.replaceV1Transforms(pipeline);
assertThat(findBatchStatefulDoFn(pipeline), equalTo((DoFn) fn));
}
use of org.apache.beam.sdk.transforms.DoFn in project beam by apache.
the class ParDoTranslation method translateParDo.
public static ParDoPayload translateParDo(AppliedPTransform<?, ?, ParDo.MultiOutput<?, ?>> appliedPTransform, SdkComponents components) throws IOException {
final ParDo.MultiOutput<?, ?> parDo = appliedPTransform.getTransform();
final Pipeline pipeline = appliedPTransform.getPipeline();
final DoFn<?, ?> doFn = parDo.getFn();
// Get main input.
Set<String> allInputs = appliedPTransform.getInputs().keySet().stream().map(TupleTag::getId).collect(Collectors.toSet());
Set<String> sideInputs = parDo.getSideInputs().values().stream().map(s -> s.getTagInternal().getId()).collect(Collectors.toSet());
String mainInputName = Iterables.getOnlyElement(Sets.difference(allInputs, sideInputs));
PCollection<?> mainInput = (PCollection<?>) appliedPTransform.getInputs().get(new TupleTag<>(mainInputName));
final DoFnSchemaInformation doFnSchemaInformation = ParDo.getDoFnSchemaInformation(doFn, mainInput);
return translateParDo((ParDo.MultiOutput) parDo, mainInput, doFnSchemaInformation, pipeline, components);
}
use of org.apache.beam.sdk.transforms.DoFn in project beam by apache.
the class OutputAndTimeBoundedSplittableProcessElementInvokerTest method testInvokeProcessElementOutputDisallowedBeforeTryClaim.
@Test
public void testInvokeProcessElementOutputDisallowedBeforeTryClaim() throws Exception {
DoFn<Void, String> brokenFn = new DoFn<Void, String>() {
@ProcessElement
public void process(ProcessContext c, RestrictionTracker<OffsetRange, Long> tracker) {
c.output("foo");
}
@GetInitialRestriction
public OffsetRange getInitialRestriction(@Element Void element) {
throw new UnsupportedOperationException("Should not be called in this test");
}
};
e.expectMessage("Output is not allowed before tryClaim()");
runTest(brokenFn, new OffsetRange(0, 5));
}
use of org.apache.beam.sdk.transforms.DoFn in project beam by apache.
the class OutputAndTimeBoundedSplittableProcessElementInvokerTest method testInvokeProcessElementOutputDisallowedAfterFailedTryClaim.
@Test
public void testInvokeProcessElementOutputDisallowedAfterFailedTryClaim() throws Exception {
DoFn<Void, String> brokenFn = new DoFn<Void, String>() {
@ProcessElement
public void process(ProcessContext c, RestrictionTracker<OffsetRange, Long> tracker) {
assertFalse(tracker.tryClaim(6L));
c.output("foo");
}
@GetInitialRestriction
public OffsetRange getInitialRestriction(@Element Void element) {
throw new UnsupportedOperationException("Should not be called in this test");
}
};
e.expectMessage("Output is not allowed after a failed tryClaim()");
runTest(brokenFn, new OffsetRange(0, 5));
}
Aggregations