use of org.talend.components.processing.definition.window.WindowProperties in project components by Talend.
the class WindowRuntimeTest method testSessionWindow.
@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();
}
use of org.talend.components.processing.definition.window.WindowProperties in project components by Talend.
the class WindowRuntimeTest method testSlidingWindow.
@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();
}
use of org.talend.components.processing.definition.window.WindowProperties in project components by Talend.
the class WindowRuntimeTest method testFixedWindow.
@Test
public void testFixedWindow() {
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(1L)), TimestampedValue.of(irB, new Instant(2L)), TimestampedValue.of(irC, new Instant(3L)));
PCollection<IndexedRecord> input = (PCollection<IndexedRecord>) p.apply(Create.timestamped(data).withCoder(LazyAvroCoder.of()));
WindowProperties windowProperties = new WindowProperties("window");
windowProperties.windowLength.setValue(2);
windowProperties.windowSlideLength.setValue(-1);
windowProperties.windowSession.setValue(false);
windowProperties.setValue("windowLength", 2);
windowProperties.setValue("windowSlideLength", -1);
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());
// ///////
// Fixed duration: 2
PAssert.that(windowed_counts).containsInAnyOrder(KV.of(irA, 1L), KV.of(irB, 1L), KV.of(irC, 1L));
p.run();
}
Aggregations