Search in sources :

Example 1 with PBegin

use of org.apache.beam.sdk.values.PBegin in project beam by apache.

the class DataflowGroupByKeyTest method testGroupByKeyServiceUnbounded.

@Test
public void testGroupByKeyServiceUnbounded() {
    Pipeline p = createTestServiceRunner();
    PCollection<KV<String, Integer>> input = p.apply(new PTransform<PBegin, PCollection<KV<String, Integer>>>() {

        @Override
        public PCollection<KV<String, Integer>> expand(PBegin input) {
            return PCollection.<KV<String, Integer>>createPrimitiveOutputInternal(input.getPipeline(), WindowingStrategy.globalDefault(), PCollection.IsBounded.UNBOUNDED).setTypeDescriptor(new TypeDescriptor<KV<String, Integer>>() {
            });
        }
    });
    thrown.expect(IllegalStateException.class);
    thrown.expectMessage("GroupByKey cannot be applied to non-bounded PCollection in the GlobalWindow without " + "a trigger. Use a Window.into or Window.triggering transform prior to GroupByKey.");
    input.apply("GroupByKey", GroupByKey.<String, Integer>create());
}
Also used : PCollection(org.apache.beam.sdk.values.PCollection) TypeDescriptor(org.apache.beam.sdk.values.TypeDescriptor) KV(org.apache.beam.sdk.values.KV) PBegin(org.apache.beam.sdk.values.PBegin) Pipeline(org.apache.beam.sdk.Pipeline) Test(org.junit.Test)

Example 2 with PBegin

use of org.apache.beam.sdk.values.PBegin in project beam by apache.

the class SdkComponentsTest method registerTransformAfterChildren.

@Test
public void registerTransformAfterChildren() throws IOException {
    Create.Values<Long> create = Create.of(1L, 2L, 3L);
    GenerateSequence createChild = GenerateSequence.from(0);
    PCollection<Long> pt = pipeline.apply(create);
    String userName = "my_transform";
    String childUserName = "my_transform/my_nesting";
    AppliedPTransform<?, ?, ?> transform = AppliedPTransform.<PBegin, PCollection<Long>, Create.Values<Long>>of(userName, pipeline.begin().expand(), pt.expand(), create, pipeline);
    AppliedPTransform<?, ?, ?> childTransform = AppliedPTransform.<PBegin, PCollection<Long>, GenerateSequence>of(childUserName, pipeline.begin().expand(), pt.expand(), createChild, pipeline);
    String childId = components.registerPTransform(childTransform, Collections.<AppliedPTransform<?, ?, ?>>emptyList());
    String parentId = components.registerPTransform(transform, Collections.<AppliedPTransform<?, ?, ?>>singletonList(childTransform));
    Components components = this.components.toComponents();
    assertThat(components.getTransformsOrThrow(parentId).getSubtransforms(0), equalTo(childId));
    assertThat(components.getTransformsOrThrow(childId).getSubtransformsCount(), equalTo(0));
}
Also used : Components(org.apache.beam.sdk.common.runner.v1.RunnerApi.Components) PCollection(org.apache.beam.sdk.values.PCollection) Create(org.apache.beam.sdk.transforms.Create) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.containsString(org.hamcrest.Matchers.containsString) PBegin(org.apache.beam.sdk.values.PBegin) GenerateSequence(org.apache.beam.sdk.io.GenerateSequence) Test(org.junit.Test)

Example 3 with PBegin

use of org.apache.beam.sdk.values.PBegin in project beam by apache.

the class SdkComponentsTest method registerTransformWithUnregisteredChildren.

/**
   * Tests that trying to register a transform which has unregistered children throws.
   */
@Test
public void registerTransformWithUnregisteredChildren() throws IOException {
    Create.Values<Long> create = Create.of(1L, 2L, 3L);
    GenerateSequence createChild = GenerateSequence.from(0);
    PCollection<Long> pt = pipeline.apply(create);
    String userName = "my_transform";
    String childUserName = "my_transform/my_nesting";
    AppliedPTransform<?, ?, ?> transform = AppliedPTransform.<PBegin, PCollection<Long>, Create.Values<Long>>of(userName, pipeline.begin().expand(), pt.expand(), create, pipeline);
    AppliedPTransform<?, ?, ?> childTransform = AppliedPTransform.<PBegin, PCollection<Long>, GenerateSequence>of(childUserName, pipeline.begin().expand(), pt.expand(), createChild, pipeline);
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage(childTransform.toString());
    components.registerPTransform(transform, Collections.<AppliedPTransform<?, ?, ?>>singletonList(childTransform));
}
Also used : PCollection(org.apache.beam.sdk.values.PCollection) Create(org.apache.beam.sdk.transforms.Create) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.containsString(org.hamcrest.Matchers.containsString) PBegin(org.apache.beam.sdk.values.PBegin) GenerateSequence(org.apache.beam.sdk.io.GenerateSequence) Test(org.junit.Test)

Example 4 with PBegin

use of org.apache.beam.sdk.values.PBegin in project beam by apache.

the class PTransformTranslationTest method generateSequence.

private static AppliedPTransform<?, ?, ?> generateSequence(Pipeline pipeline) {
    GenerateSequence sequence = GenerateSequence.from(0);
    PCollection<Long> pcollection = pipeline.apply(sequence);
    return AppliedPTransform.<PBegin, PCollection<Long>, GenerateSequence>of("Count", pipeline.begin().expand(), pcollection.expand(), sequence, pipeline);
}
Also used : PCollection(org.apache.beam.sdk.values.PCollection) PBegin(org.apache.beam.sdk.values.PBegin) GenerateSequence(org.apache.beam.sdk.io.GenerateSequence)

Example 5 with PBegin

use of org.apache.beam.sdk.values.PBegin in project beam by apache.

the class CreateTest method testCreateTimestampedDefaultOutputCoderUsingCoder.

@Test
public void testCreateTimestampedDefaultOutputCoderUsingCoder() throws Exception {
    Coder<Record> coder = new RecordCoder();
    PBegin pBegin = PBegin.in(p);
    Create.TimestampedValues<Record> values = Create.timestamped(TimestampedValue.of(new Record(), new Instant(0)), TimestampedValue.<Record>of(new Record2(), new Instant(0))).withCoder(coder);
    Coder<Record> defaultCoder = values.getDefaultOutputCoder(pBegin);
    assertThat(defaultCoder, equalTo(coder));
}
Also used : Instant(org.joda.time.Instant) PBegin(org.apache.beam.sdk.values.PBegin) Test(org.junit.Test)

Aggregations

PBegin (org.apache.beam.sdk.values.PBegin)13 Test (org.junit.Test)12 PCollection (org.apache.beam.sdk.values.PCollection)7 Create (org.apache.beam.sdk.transforms.Create)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)4 GenerateSequence (org.apache.beam.sdk.io.GenerateSequence)3 Instant (org.joda.time.Instant)2 HashSet (java.util.HashSet)1 Pipeline (org.apache.beam.sdk.Pipeline)1 PipelineVisitor (org.apache.beam.sdk.Pipeline.PipelineVisitor)1 Defaults (org.apache.beam.sdk.Pipeline.PipelineVisitor.Defaults)1 Components (org.apache.beam.sdk.common.runner.v1.RunnerApi.Components)1 Read (org.apache.beam.sdk.io.Read)1 Node (org.apache.beam.sdk.runners.TransformHierarchy.Node)1 DisplayData (org.apache.beam.sdk.transforms.display.DisplayData)1 DisplayDataEvaluator (org.apache.beam.sdk.transforms.display.DisplayDataEvaluator)1 KV (org.apache.beam.sdk.values.KV)1 PValue (org.apache.beam.sdk.values.PValue)1 TaggedPValue (org.apache.beam.sdk.values.TaggedPValue)1