use of org.apache.beam.sdk.coders.BigEndianLongCoder in project beam by apache.
the class SdkComponentsTest method translatePipeline.
@Test
public void translatePipeline() {
BigEndianLongCoder customCoder = BigEndianLongCoder.of();
PCollection<Long> elems = pipeline.apply(GenerateSequence.from(0L).to(207L));
PCollection<Long> counted = elems.apply(Count.<Long>globally()).setCoder(customCoder);
PCollection<Long> windowed = counted.apply(Window.<Long>into(FixedWindows.of(Duration.standardMinutes(7))).triggering(AfterWatermark.pastEndOfWindow().withEarlyFirings(AfterPane.elementCountAtLeast(19))).accumulatingFiredPanes().withAllowedLateness(Duration.standardMinutes(3L)));
final WindowingStrategy<?, ?> windowedStrategy = windowed.getWindowingStrategy();
PCollection<KV<String, Long>> keyed = windowed.apply(WithKeys.<String, Long>of("foo"));
PCollection<KV<String, Iterable<Long>>> grouped = keyed.apply(GroupByKey.<String, Long>create());
final RunnerApi.Pipeline pipelineProto = SdkComponents.translatePipeline(pipeline);
pipeline.traverseTopologically(new PipelineVisitor.Defaults() {
Set<Node> transforms = new HashSet<>();
Set<PCollection<?>> pcollections = new HashSet<>();
Set<Equivalence.Wrapper<? extends Coder<?>>> coders = new HashSet<>();
Set<WindowingStrategy<?, ?>> windowingStrategies = new HashSet<>();
@Override
public void leaveCompositeTransform(Node node) {
if (node.isRootNode()) {
assertThat("Unexpected number of PTransforms", pipelineProto.getComponents().getTransformsCount(), equalTo(transforms.size()));
assertThat("Unexpected number of PCollections", pipelineProto.getComponents().getPcollectionsCount(), equalTo(pcollections.size()));
assertThat("Unexpected number of Coders", pipelineProto.getComponents().getCodersCount(), equalTo(coders.size()));
assertThat("Unexpected number of Windowing Strategies", pipelineProto.getComponents().getWindowingStrategiesCount(), equalTo(windowingStrategies.size()));
} else {
transforms.add(node);
}
}
@Override
public void visitPrimitiveTransform(Node node) {
transforms.add(node);
}
@Override
public void visitValue(PValue value, Node producer) {
if (value instanceof PCollection) {
PCollection pc = (PCollection) value;
pcollections.add(pc);
addCoders(pc.getCoder());
windowingStrategies.add(pc.getWindowingStrategy());
addCoders(pc.getWindowingStrategy().getWindowFn().windowCoder());
}
}
private void addCoders(Coder<?> coder) {
coders.add(Equivalence.<Coder<?>>identity().wrap(coder));
if (coder instanceof StructuredCoder) {
for (Coder<?> component : ((StructuredCoder<?>) coder).getComponents()) {
addCoders(component);
}
}
}
});
}
use of org.apache.beam.sdk.coders.BigEndianLongCoder in project beam by apache.
the class PipelineTranslationTest method testPipelines.
@Parameters(name = "{index}")
public static Iterable<Pipeline> testPipelines() {
Pipeline trivialPipeline = Pipeline.create();
trivialPipeline.apply(Create.of(1, 2, 3));
Pipeline sideInputPipeline = Pipeline.create();
final PCollectionView<String> singletonView = sideInputPipeline.apply(Create.of("foo")).apply(View.asSingleton());
sideInputPipeline.apply(Create.of("main input")).apply(ParDo.of(new DoFn<String, String>() {
@ProcessElement
public void process(ProcessContext c) {
// actually never executed and no effect on translation
c.sideInput(singletonView);
}
}).withSideInputs(singletonView));
Pipeline complexPipeline = Pipeline.create();
BigEndianLongCoder customCoder = BigEndianLongCoder.of();
PCollection<Long> elems = complexPipeline.apply(GenerateSequence.from(0L).to(207L));
PCollection<Long> counted = elems.apply(Count.globally()).setCoder(customCoder);
PCollection<Long> windowed = counted.apply(Window.<Long>into(FixedWindows.of(Duration.standardMinutes(7))).triggering(AfterWatermark.pastEndOfWindow().withLateFirings(AfterPane.elementCountAtLeast(19))).accumulatingFiredPanes().withAllowedLateness(Duration.standardMinutes(3L)));
windowed.getWindowingStrategy();
PCollection<KV<String, Long>> keyed = windowed.apply(WithKeys.of("foo"));
keyed.apply(GroupByKey.create());
return ImmutableList.of(trivialPipeline, sideInputPipeline, complexPipeline);
}
use of org.apache.beam.sdk.coders.BigEndianLongCoder in project beam by apache.
the class LatestTest method testGloballyOutputCoder.
@Test
public void testGloballyOutputCoder() {
p.enableAbandonedNodeEnforcement(false);
BigEndianLongCoder inputCoder = BigEndianLongCoder.of();
PCollection<Long> output = p.apply(Create.of(1L, 2L).withCoder(inputCoder)).apply(Latest.globally());
Coder<Long> outputCoder = output.getCoder();
assertThat(outputCoder, instanceOf(NullableCoder.class));
assertEquals(inputCoder, ((NullableCoder<?>) outputCoder).getValueCoder());
}
Aggregations