Search in sources :

Example 16 with TimeWindow

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));
}
Also used : TimeWindow(org.apache.flink.table.runtime.operators.window.TimeWindow) Test(org.junit.Test)

Example 17 with TimeWindow

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));
}
Also used : TimeWindow(org.apache.flink.table.runtime.operators.window.TimeWindow) Test(org.junit.Test)

Aggregations

TimeWindow (org.apache.flink.table.runtime.operators.window.TimeWindow)17 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)6 GenericRowData (org.apache.flink.table.data.GenericRowData)3 RowData (org.apache.flink.table.data.RowData)3 JoinedRowData (org.apache.flink.table.data.utils.JoinedRowData)3 List (java.util.List)2 TreeSet (java.util.TreeSet)2 UpdatableRowData (org.apache.flink.table.data.UpdatableRowData)2 ArgumentMatcher (org.mockito.ArgumentMatcher)2 IOException (java.io.IOException)1 ZoneId (java.time.ZoneId)1 Arrays.asList (java.util.Arrays.asList)1 Collections.singletonList (java.util.Collections.singletonList)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Transformation (org.apache.flink.api.dag.Transformation)1 ByteArrayOutputStreamWithPos (org.apache.flink.core.memory.ByteArrayOutputStreamWithPos)1 DataInputDeserializer (org.apache.flink.core.memory.DataInputDeserializer)1