Search in sources :

Example 11 with ApexPipelineOptions

use of org.apache.beam.runners.apex.ApexPipelineOptions in project beam by apache.

the class FlattenPCollectionTranslatorTest method testFlattenSingleCollection.

@Test
public void testFlattenSingleCollection() {
    ApexPipelineOptions options = PipelineOptionsFactory.as(ApexPipelineOptions.class);
    Pipeline p = Pipeline.create();
    PCollection<String> single = p.apply(Create.of(Collections.singletonList("1")));
    PCollectionList.of(single).apply(Flatten.<String>pCollections()).apply(ParDo.of(new EmbeddedCollector()));
    DAG dag = TestApexRunner.translate(p, options);
    Assert.assertNotNull(dag.getOperatorMeta("ParDo(EmbeddedCollector)/ParMultiDo(EmbeddedCollector)"));
}
Also used : DAG(com.datatorrent.api.DAG) ApexPipelineOptions(org.apache.beam.runners.apex.ApexPipelineOptions) Pipeline(org.apache.beam.sdk.Pipeline) Test(org.junit.Test)

Example 12 with ApexPipelineOptions

use of org.apache.beam.runners.apex.ApexPipelineOptions in project beam by apache.

the class GroupByKeyTranslatorTest method test.

@SuppressWarnings({ "unchecked" })
@Test
public void test() throws Exception {
    ApexPipelineOptions options = PipelineOptionsFactory.as(ApexPipelineOptions.class);
    options.setApplicationName("GroupByKey");
    options.setRunner(ApexRunner.class);
    Pipeline p = Pipeline.create(options);
    List<KV<String, Instant>> data = Lists.newArrayList(KV.of("foo", new Instant(1000)), KV.of("foo", new Instant(1000)), KV.of("foo", new Instant(2000)), KV.of("bar", new Instant(1000)), KV.of("bar", new Instant(2000)), KV.of("bar", new Instant(2000)));
    // expected results assume outputAtLatestInputTimestamp
    List<KV<Instant, KV<String, Long>>> expected = Lists.newArrayList(KV.of(new Instant(1000), KV.of("foo", 2L)), KV.of(new Instant(1000), KV.of("bar", 1L)), KV.of(new Instant(2000), KV.of("foo", 1L)), KV.of(new Instant(2000), KV.of("bar", 2L)));
    p.apply(Read.from(new TestSource(data, new Instant(5000)))).apply(Window.<String>into(FixedWindows.of(Duration.standardSeconds(1))).withTimestampCombiner(TimestampCombiner.LATEST)).apply(Count.<String>perElement()).apply(ParDo.of(new KeyedByTimestamp<KV<String, Long>>())).apply(ParDo.of(new EmbeddedCollector()));
    ApexRunnerResult result = (ApexRunnerResult) p.run();
    result.getApexDAG();
    long timeout = System.currentTimeMillis() + 30000;
    while (System.currentTimeMillis() < timeout) {
        if (EmbeddedCollector.RESULTS.containsAll(expected)) {
            break;
        }
        Thread.sleep(1000);
    }
    Assert.assertEquals(Sets.newHashSet(expected), EmbeddedCollector.RESULTS);
}
Also used : Instant(org.joda.time.Instant) ApexRunnerResult(org.apache.beam.runners.apex.ApexRunnerResult) KV(org.apache.beam.sdk.values.KV) Pipeline(org.apache.beam.sdk.Pipeline) ApexPipelineOptions(org.apache.beam.runners.apex.ApexPipelineOptions) Test(org.junit.Test)

Aggregations

ApexPipelineOptions (org.apache.beam.runners.apex.ApexPipelineOptions)12 Pipeline (org.apache.beam.sdk.Pipeline)12 Test (org.junit.Test)12 ApexRunnerResult (org.apache.beam.runners.apex.ApexRunnerResult)7 DAG (com.datatorrent.api.DAG)4 KV (org.apache.beam.sdk.values.KV)3 Sink (com.datatorrent.api.Sink)2 ApexStateInternals (org.apache.beam.runners.apex.translation.utils.ApexStateInternals)2 ApexStreamTuple (org.apache.beam.runners.apex.translation.utils.ApexStreamTuple)2 WindowedValue (org.apache.beam.sdk.util.WindowedValue)2 Instant (org.joda.time.Instant)2 ArrayList (java.util.ArrayList)1 Pattern (java.util.regex.Pattern)1 ApexRunner (org.apache.beam.runners.apex.ApexRunner)1 TestApexRunner (org.apache.beam.runners.apex.TestApexRunner)1 ApexGroupByKeyOperator (org.apache.beam.runners.apex.translation.operators.ApexGroupByKeyOperator)1 ApexParDoOperator (org.apache.beam.runners.apex.translation.operators.ApexParDoOperator)1 CollectionSource (org.apache.beam.runners.apex.translation.utils.CollectionSource)1 TestPipeline (org.apache.beam.sdk.testing.TestPipeline)1 BoundedWindow (org.apache.beam.sdk.transforms.windowing.BoundedWindow)1