use of org.apache.flink.table.runtime.operators.window.TimeWindow in project flink by apache.
the class SlidingWindowAssignerTest method testWindowAssignmentWithOffset.
@SuppressWarnings("unchecked")
@Test
public void testWindowAssignmentWithOffset() {
SlidingWindowAssigner assigner = SlidingWindowAssigner.of(Duration.ofMillis(5000), Duration.ofMillis(1000)).withOffset(Duration.ofMillis(100));
assertThat(assigner.assignWindows(ELEMENT, 100L), containsInAnyOrder(timeWindow(-3900, 1100), timeWindow(-2900, 2100), timeWindow(-1900, 3100), timeWindow(-900, 4100), timeWindow(100, 5100)));
assertThat(assigner.assignWindows(ELEMENT, 5099L), containsInAnyOrder(timeWindow(100, 5100), timeWindow(1100, 6100), timeWindow(2100, 7100), timeWindow(3100, 8100), timeWindow(4100, 9100)));
assertThat(assigner.assignWindows(ELEMENT, 5100L), containsInAnyOrder(timeWindow(1100, 6100), timeWindow(2100, 7100), timeWindow(3100, 8100), timeWindow(4100, 9100), timeWindow(5100, 10100)));
// test pane
assertEquals(assigner.assignPane(ELEMENT, 100L), new TimeWindow(100, 1100));
assertEquals(assigner.assignPane(ELEMENT, 5099L), new TimeWindow(4100, 5100));
assertEquals(assigner.assignPane(ELEMENT, 5100L), new TimeWindow(5100, 6100));
assertThat(assigner.splitIntoPanes(new TimeWindow(1100, 6100)), contains(timeWindow(1100, 2100), timeWindow(2100, 3100), timeWindow(3100, 4100), timeWindow(4100, 5100), timeWindow(5100, 6100)));
assertThat(assigner.splitIntoPanes(new TimeWindow(3100, 8100)), contains(timeWindow(3100, 4100), timeWindow(4100, 5100), timeWindow(5100, 6100), timeWindow(6100, 7100), timeWindow(7100, 8100)));
assertEquals(assigner.getLastWindow(new TimeWindow(4100, 5100)), new TimeWindow(4100, 9100));
assertEquals(assigner.getLastWindow(new TimeWindow(2100, 3100)), new TimeWindow(2100, 7100));
}
use of org.apache.flink.table.runtime.operators.window.TimeWindow in project flink by apache.
the class SlidingWindowAssignerTest method testWindowAssignment.
@SuppressWarnings("unchecked")
@Test
public void testWindowAssignment() {
SlidingWindowAssigner assigner = SlidingWindowAssigner.of(Duration.ofMillis(5000), Duration.ofMillis(1000));
assertThat(assigner.assignWindows(ELEMENT, 0L), containsInAnyOrder(timeWindow(-4000, 1000), timeWindow(-3000, 2000), timeWindow(-2000, 3000), timeWindow(-1000, 4000), timeWindow(0, 5000)));
assertThat(assigner.assignWindows(ELEMENT, 4999L), containsInAnyOrder(timeWindow(0, 5000), timeWindow(1000, 6000), timeWindow(2000, 7000), timeWindow(3000, 8000), timeWindow(4000, 9000)));
assertThat(assigner.assignWindows(ELEMENT, 5000L), containsInAnyOrder(timeWindow(1000, 6000), timeWindow(2000, 7000), timeWindow(3000, 8000), timeWindow(4000, 9000), timeWindow(5000, 10000)));
// test pane
assertEquals(assigner.assignPane(ELEMENT, 0L), new TimeWindow(0, 1000));
assertEquals(assigner.assignPane(ELEMENT, 4999L), new TimeWindow(4000, 5000));
assertEquals(assigner.assignPane(ELEMENT, 5000L), new TimeWindow(5000, 6000));
assertThat(assigner.splitIntoPanes(new TimeWindow(0, 5000)), contains(timeWindow(0, 1000), timeWindow(1000, 2000), timeWindow(2000, 3000), timeWindow(3000, 4000), timeWindow(4000, 5000)));
assertThat(assigner.splitIntoPanes(new TimeWindow(3000, 8000)), contains(timeWindow(3000, 4000), timeWindow(4000, 5000), timeWindow(5000, 6000), timeWindow(6000, 7000), timeWindow(7000, 8000)));
assertEquals(assigner.getLastWindow(new TimeWindow(4000, 5000)), new TimeWindow(4000, 9000));
assertEquals(assigner.getLastWindow(new TimeWindow(2000, 3000)), new TimeWindow(2000, 7000));
}
Aggregations