Java Code Examples for org.apache.beam.sdk.transforms.Create#timestamped()
The following examples show how to use
org.apache.beam.sdk.transforms.Create#timestamped() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataflowRunnerTest.java From beam with Apache License 2.0 | 6 votes |
@Test public void testApplyIsScopedToExactClass() throws IOException { DataflowPipelineOptions options = buildPipelineOptions(); Pipeline p = Pipeline.create(options); Create.TimestampedValues<String> transform = Create.timestamped(Arrays.asList(TimestampedValue.of("TestString", Instant.now()))); p.apply(transform); CompositeTransformRecorder recorder = new CompositeTransformRecorder(); p.traverseTopologically(recorder); // The recorder will also have seen a Create.Values composite as well, but we can't obtain that // transform. assertThat( "Expected to have seen CreateTimestamped composite transform.", recorder.getCompositeTransforms(), hasItem(transform)); assertThat( "Expected to have two composites, CreateTimestamped and Create.Values", recorder.getCompositeTransforms(), hasItem(Matchers.<PTransform<?, ?>>isA((Class) Create.Values.class))); }
Example 2
Source File: BeamModelTest.java From streamingbook with Apache License 2.0 | 5 votes |
Create.TimestampedValues<KV<String, Integer>> createBatch() { return Create.timestamped( score("TeamX", 5, "12:00:26"), score("TeamX", 7, "12:02:26"), score("TeamX", 3, "12:03:39"), score("TeamX", 4, "12:04:19"), score("TeamX", 8, "12:03:06"), score("TeamX", 3, "12:06:39"), score("TeamX", 9, "12:01:26"), score("TeamX", 8, "12:07:26"), score("TeamX", 1, "12:07:46")); }
Example 3
Source File: WindowRuntimeTest.java From components with Apache License 2.0 | 4 votes |
@Test public void testSlidingWindow() { PipelineOptions options = PipelineOptionsFactory.create(); options.setRunner(DirectRunner.class); final Pipeline p = Pipeline.create(options); /* * // creation of PCollection with different timestamp PCollection<IndexedRecord> */ List<TimestampedValue<IndexedRecord>> data = Arrays.asList( // TimestampedValue.of(irA, new Instant(0L)), // TimestampedValue.of(irB, new Instant(0L)), // TimestampedValue.of(irC, new Instant(1L)), // TimestampedValue.of(irA, new Instant(2L)), // TimestampedValue.of(irA, new Instant(2L)), // TimestampedValue.of(irB, new Instant(2L)), // TimestampedValue.of(irB, new Instant(3L)), // TimestampedValue.of(irC, new Instant(3L)), // TimestampedValue.of(irA, new Instant(4L))); Create.TimestampedValues<IndexedRecord> pt = Create.timestamped(data); pt = (Create.TimestampedValues<IndexedRecord>) pt.withCoder(LazyAvroCoder.of()); PCollection<IndexedRecord> input = p.apply(pt); WindowProperties windowProperties = new WindowProperties("window"); windowProperties.setValue("windowLength", 4); windowProperties.setValue("windowSlideLength", 2); windowProperties.setValue("windowSession", false); WindowRuntime windowRun = new WindowRuntime(); windowRun.initialize(null, windowProperties); PCollection<IndexedRecord> test = windowRun.expand(input); PCollection<KV<IndexedRecord, Long>> windowed_counts = test.apply(Count.<IndexedRecord> perElement()); // window duration: 4 - sliding: 2 PAssert.that(windowed_counts).containsInAnyOrder( // KV.of(irA, 1L), // KV.of(irA, 1L), // KV.of(irA, 3L), // KV.of(irA, 3L), // KV.of(irB, 1L), // KV.of(irB, 3L), // KV.of(irB, 2L), // KV.of(irC, 1L), // KV.of(irC, 1L), // KV.of(irC, 2L)); p.run(); }
Example 4
Source File: WindowRuntimeTest.java From components with Apache License 2.0 | 4 votes |
@Test public void testSessionWindow() { PipelineOptions options = PipelineOptionsFactory.create(); options.setRunner(DirectRunner.class); final Pipeline p = Pipeline.create(options); /* * // creation of PCollection with different timestamp PCollection<IndexedRecord> */ List<TimestampedValue<IndexedRecord>> data = Arrays.asList( // TimestampedValue.of(irA, new Instant(0L)), // TimestampedValue.of(irB, new Instant(0L)), // TimestampedValue.of(irC, new Instant(1L)), // TimestampedValue.of(irA, new Instant(2L)), // TimestampedValue.of(irA, new Instant(2L)), // TimestampedValue.of(irB, new Instant(2L)), // TimestampedValue.of(irB, new Instant(30L)), // TimestampedValue.of(irA, new Instant(30L)), // TimestampedValue.of(irA, new Instant(50L)), // TimestampedValue.of(irC, new Instant(55L)), // TimestampedValue.of(irA, new Instant(59L))); Create.TimestampedValues<IndexedRecord> pt = Create.timestamped(data); pt = (Create.TimestampedValues<IndexedRecord>) pt.withCoder(LazyAvroCoder.of()); PCollection<IndexedRecord> input = p.apply(pt); WindowProperties windowProperties = new WindowProperties("window"); windowProperties.setValue("windowLength", 10); windowProperties.setValue("windowSlideLength", -1); windowProperties.setValue("windowSession", true); WindowRuntime windowRun = new WindowRuntime(); windowRun.initialize(null, windowProperties); PCollection<IndexedRecord> test = windowRun.expand(input); PCollection<KV<IndexedRecord, Long>> windowed_counts = test.apply(Count.<IndexedRecord> perElement()); // window duration: 4 - sliding: 2 PAssert.that(windowed_counts).containsInAnyOrder( // KV.of(irA, 3L), // KV.of(irB, 2L), // KV.of(irC, 1L), // KV.of(irB, 1L), // KV.of(irA, 1L), // KV.of(irA, 2L), // KV.of(irC, 1L)); p.run(); }