use of org.apache.beam.sdk.values.PBegin in project beam by apache.
the class SdkComponentsTest method registerTransformNoChildren.
@Test
public void registerTransformNoChildren() throws IOException {
Create.Values<Integer> create = Create.of(1, 2, 3);
PCollection<Integer> pt = pipeline.apply(create);
String userName = "my_transform/my_nesting";
AppliedPTransform<?, ?, ?> transform = AppliedPTransform.<PBegin, PCollection<Integer>, Create.Values<Integer>>of(userName, pipeline.begin().expand(), pt.expand(), create, pipeline);
String componentName = components.registerPTransform(transform, Collections.<AppliedPTransform<?, ?, ?>>emptyList());
assertThat(componentName, equalTo(userName));
assertThat(components.getExistingPTransformId(transform), equalTo(componentName));
}
use of org.apache.beam.sdk.values.PBegin in project beam by apache.
the class SdkComponentsTest method registerTransformNullComponents.
@Test
public void registerTransformNullComponents() throws IOException {
Create.Values<Integer> create = Create.of(1, 2, 3);
PCollection<Integer> pt = pipeline.apply(create);
String userName = "my_transform/my_nesting";
AppliedPTransform<?, ?, ?> transform = AppliedPTransform.<PBegin, PCollection<Integer>, Create.Values<Integer>>of(userName, pipeline.begin().expand(), pt.expand(), create, pipeline);
thrown.expect(NullPointerException.class);
thrown.expectMessage("child nodes may not be null");
components.registerPTransform(transform, null);
}
use of org.apache.beam.sdk.values.PBegin in project beam by apache.
the class TransformHierarchyTest method visitVisitsAllPushed.
@Test
public void visitVisitsAllPushed() {
TransformHierarchy.Node root = hierarchy.getCurrent();
PBegin begin = PBegin.in(pipeline);
Create.Values<Long> create = Create.of(1L);
Read.Bounded<Long> read = Read.from(CountingSource.upTo(1L));
PCollection<Long> created = PCollection.createPrimitiveOutputInternal(pipeline, WindowingStrategy.globalDefault(), IsBounded.BOUNDED);
SingleOutput<Long, Long> pardo = ParDo.of(new DoFn<Long, Long>() {
@ProcessElement
public void processElement(ProcessContext ctxt) {
ctxt.output(ctxt.element());
}
});
PCollection<Long> mapped = PCollection.createPrimitiveOutputInternal(pipeline, WindowingStrategy.globalDefault(), IsBounded.BOUNDED);
TransformHierarchy.Node compositeNode = hierarchy.pushNode("Create", begin, create);
hierarchy.finishSpecifyingInput();
assertThat(hierarchy.getCurrent(), equalTo(compositeNode));
assertThat(compositeNode.getInputs().entrySet(), Matchers.empty());
assertThat(compositeNode.getTransform(), Matchers.<PTransform<?, ?>>equalTo(create));
// Not yet set
assertThat(compositeNode.getOutputs().entrySet(), Matchers.emptyIterable());
assertThat(compositeNode.getEnclosingNode().isRootNode(), is(true));
TransformHierarchy.Node primitiveNode = hierarchy.pushNode("Create/Read", begin, read);
assertThat(hierarchy.getCurrent(), equalTo(primitiveNode));
hierarchy.finishSpecifyingInput();
hierarchy.setOutput(created);
hierarchy.popNode();
assertThat(primitiveNode.getOutputs().values(), Matchers.<PValue>containsInAnyOrder(created));
assertThat(primitiveNode.getInputs().entrySet(), Matchers.emptyIterable());
assertThat(primitiveNode.getTransform(), Matchers.<PTransform<?, ?>>equalTo(read));
assertThat(primitiveNode.getEnclosingNode(), equalTo(compositeNode));
hierarchy.setOutput(created);
// The composite is listed as outputting a PValue created by the contained primitive
assertThat(compositeNode.getOutputs().values(), Matchers.<PValue>containsInAnyOrder(created));
// The producer of that PValue is still the primitive in which it is first output
assertThat(hierarchy.getProducer(created), equalTo(primitiveNode));
hierarchy.popNode();
TransformHierarchy.Node otherPrimitive = hierarchy.pushNode("ParDo", created, pardo);
hierarchy.finishSpecifyingInput();
hierarchy.setOutput(mapped);
hierarchy.popNode();
final Set<TransformHierarchy.Node> visitedCompositeNodes = new HashSet<>();
final Set<TransformHierarchy.Node> visitedPrimitiveNodes = new HashSet<>();
final Set<PValue> visitedValuesInVisitor = new HashSet<>();
Set<PValue> visitedValues = hierarchy.visit(new PipelineVisitor.Defaults() {
@Override
public CompositeBehavior enterCompositeTransform(TransformHierarchy.Node node) {
visitedCompositeNodes.add(node);
return CompositeBehavior.ENTER_TRANSFORM;
}
@Override
public void visitPrimitiveTransform(TransformHierarchy.Node node) {
visitedPrimitiveNodes.add(node);
}
@Override
public void visitValue(PValue value, TransformHierarchy.Node producer) {
visitedValuesInVisitor.add(value);
}
});
assertThat(visitedCompositeNodes, containsInAnyOrder(root, compositeNode));
assertThat(visitedPrimitiveNodes, containsInAnyOrder(primitiveNode, otherPrimitive));
assertThat(visitedValuesInVisitor, Matchers.<PValue>containsInAnyOrder(created, mapped));
assertThat(visitedValuesInVisitor, equalTo(visitedValues));
}
Aggregations