use of org.apache.flink.table.runtime.operators.window.TimeWindow in project flink by apache.
the class SessionWindowAssigner method mergeWindows.
@Override
public void mergeWindows(TimeWindow newWindow, NavigableSet<TimeWindow> sortedWindows, MergeCallback<TimeWindow> callback) {
TimeWindow ceiling = sortedWindows.ceiling(newWindow);
TimeWindow floor = sortedWindows.floor(newWindow);
Collection<TimeWindow> mergedWindows = new HashSet<>();
TimeWindow mergeResult = newWindow;
if (ceiling != null) {
mergeResult = mergeWindow(mergeResult, ceiling, mergedWindows);
}
if (floor != null) {
mergeResult = mergeWindow(mergeResult, floor, mergedWindows);
}
if (!mergedWindows.isEmpty()) {
// merge happens, add newWindow into the collection as well.
mergedWindows.add(newWindow);
callback.merge(mergeResult, mergedWindows);
}
}
use of org.apache.flink.table.runtime.operators.window.TimeWindow in project flink by apache.
the class SessionWindowAssignerTest method testMergeCoveringWindow.
@SuppressWarnings("unchecked")
@Test
public void testMergeCoveringWindow() {
MergingWindowAssigner.MergeCallback callback = mock(MergingWindowAssigner.MergeCallback.class);
SessionWindowAssigner assigner = SessionWindowAssigner.withGap(Duration.ofMillis(5000));
TreeSet<TimeWindow> sortedWindows = new TreeSet<>();
sortedWindows.addAll(Arrays.asList(new TimeWindow(1, 4), new TimeWindow(5, 7), new TimeWindow(9, 10)));
assigner.mergeWindows(new TimeWindow(3, 6), sortedWindows, callback);
verify(callback, times(1)).merge(eq(new TimeWindow(1, 7)), argThat((ArgumentMatcher<Collection<TimeWindow>>) timeWindows -> containsInAnyOrder(new TimeWindow(1, 4), new TimeWindow(5, 7), new TimeWindow(3, 6)).matches(timeWindows)));
}
use of org.apache.flink.table.runtime.operators.window.TimeWindow in project flink by apache.
the class SessionWindowAssignerTest method testMergeConsecutiveWindows.
@SuppressWarnings("unchecked")
@Test
public void testMergeConsecutiveWindows() {
MergingWindowAssigner.MergeCallback callback = mock(MergingWindowAssigner.MergeCallback.class);
SessionWindowAssigner assigner = SessionWindowAssigner.withGap(Duration.ofMillis(5000));
TreeSet<TimeWindow> sortedWindows = new TreeSet<>();
sortedWindows.addAll(Arrays.asList(new TimeWindow(0, 1), new TimeWindow(2, 3), new TimeWindow(4, 5), new TimeWindow(7, 8)));
assigner.mergeWindows(new TimeWindow(1, 2), sortedWindows, callback);
verify(callback, times(1)).merge(eq(new TimeWindow(0, 3)), argThat((ArgumentMatcher<Collection<TimeWindow>>) timeWindows -> containsInAnyOrder(new TimeWindow(0, 1), new TimeWindow(1, 2), new TimeWindow(2, 3)).matches(timeWindows)));
}
use of org.apache.flink.table.runtime.operators.window.TimeWindow in project flink by apache.
the class HeapWindowsGroupingTest method testInvalidWindowTrigger.
@Test(expected = IllegalStateException.class)
public void testInvalidWindowTrigger() throws IOException {
Long[] ts = new Long[] { 8L };
RowIterator<BinaryRowData> iterator = new HeapWindowsGroupingTest.TestInputIterator(ts);
HeapWindowsGrouping grouping = new HeapWindowsGrouping(5000, 0L, 8L, 4L, 0, false);
grouping.addInputToBuffer(iterator.getRow());
System.out.println("valid window trigger");
RowIterator<BinaryRowData> iter = grouping.buildTriggerWindowElementsIterator();
TimeWindow window = grouping.getTriggerWindow();
List<Long> buffer = new ArrayList<>();
while (iter.advanceNext()) {
buffer.add(iter.getRow().getLong(0));
}
assertEquals(TimeWindow.of(0, 8L), window);
assertEquals(Collections.emptyList(), buffer);
System.out.println("try invalid window trigger");
grouping.buildTriggerWindowElementsIterator();
}
use of org.apache.flink.table.runtime.operators.window.TimeWindow in project flink by apache.
the class HeapWindowsGroupingTest method verify.
private void verify(int limit, Long[] ts, long windowSize, long slideSize, List<List<Long>> expected, List<TimeWindow> expectedWindows) throws IOException {
List<List<Long>> actual = new ArrayList<>();
List<TimeWindow> windows = new ArrayList<>();
HeapWindowsGrouping grouping = new HeapWindowsGrouping(limit, 0L, windowSize, slideSize, 0, false);
RowIterator<BinaryRowData> iterator = new HeapWindowsGroupingTest.TestInputIterator(ts);
while (iterator.advanceNext()) {
BinaryRowData input = iterator.getRow();
grouping.addInputToBuffer(input);
processTriggerWindow(actual, windows, grouping);
}
grouping.advanceWatermarkToTriggerAllWindows();
processTriggerWindow(actual, windows, grouping);
assertEquals(expectedWindows, windows);
assertEquals(expected, actual);
}
Aggregations