use of org.apache.flink.table.runtime.operators.window.TimeWindow in project flink by apache.
the class BatchArrowPythonGroupWindowAggregateFunctionOperator method emitResult.
@Override
@SuppressWarnings("ConstantConditions")
public void emitResult(Tuple2<byte[], Integer> resultTuple) throws Exception {
byte[] udafResult = resultTuple.f0;
int length = resultTuple.f1;
bais.setBuffer(udafResult, 0, length);
int rowCount = arrowSerializer.load();
for (int i = 0; i < rowCount; i++) {
Tuple2<RowData, TimeWindow> input = inputKeyAndWindow.poll();
RowData key = input.f0;
TimeWindow window = input.f1;
setWindowProperty(window);
windowAggResult.replace(key, arrowSerializer.read(i));
rowDataWrapper.collect(reuseJoinedRow.replace(windowAggResult, windowProperty));
}
arrowSerializer.resetReader();
}
use of org.apache.flink.table.runtime.operators.window.TimeWindow in project flink by apache.
the class BatchArrowPythonGroupWindowAggregateFunctionOperator method triggerWindowProcess.
private void triggerWindowProcess() throws Exception {
while (windowsGrouping.hasTriggerWindow()) {
RowIterator<BinaryRowData> elementIterator = windowsGrouping.buildTriggerWindowElementsIterator();
while (elementIterator.advanceNext()) {
BinaryRowData winElement = elementIterator.getRow();
arrowSerializer.write(getFunctionInput(winElement));
currentBatchCount++;
}
if (currentBatchCount > 0) {
TimeWindow currentWindow = windowsGrouping.getTriggerWindow();
inputKeyAndWindow.add(Tuple2.of(lastGroupSet, currentWindow));
arrowSerializer.finishCurrentBatch();
pythonFunctionRunner.process(baos.toByteArray());
elementCount += currentBatchCount;
checkInvokeFinishBundleByCount();
currentBatchCount = 0;
baos.reset();
arrowSerializer.resetWriter();
}
}
}
use of org.apache.flink.table.runtime.operators.window.TimeWindow in project flink by apache.
the class CumulativeWindowAssignerTest method testWindowAssignment.
@SuppressWarnings("unchecked")
@Test
public void testWindowAssignment() {
CumulativeWindowAssigner assigner = CumulativeWindowAssigner.of(Duration.ofMillis(5000), Duration.ofMillis(1000));
assertThat(assigner.assignWindows(ELEMENT, 0L), containsInAnyOrder(timeWindow(0, 1000), timeWindow(0, 2000), timeWindow(0, 3000), timeWindow(0, 4000), timeWindow(0, 5000)));
assertThat(assigner.assignWindows(ELEMENT, 4999L), contains(timeWindow(0, 5000)));
assertThat(assigner.assignWindows(ELEMENT, 5000L), containsInAnyOrder(timeWindow(5000, 6000), timeWindow(5000, 7000), timeWindow(5000, 8000), timeWindow(5000, 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, 2000), new TimeWindow(2000, 3000));
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(5000, 8000)), contains(timeWindow(5000, 6000), timeWindow(6000, 7000), timeWindow(7000, 8000)));
assertEquals(assigner.getLastWindow(new TimeWindow(4000, 5000)), new TimeWindow(0, 5000));
assertEquals(assigner.getLastWindow(new TimeWindow(2000, 3000)), new TimeWindow(0, 5000));
assertEquals(assigner.getLastWindow(new TimeWindow(7000, 8000)), new TimeWindow(5000, 10000));
}
use of org.apache.flink.table.runtime.operators.window.TimeWindow in project flink by apache.
the class CumulativeWindowAssignerTest method testWindowAssignmentWithOffset.
@SuppressWarnings("unchecked")
@Test
public void testWindowAssignmentWithOffset() {
CumulativeWindowAssigner assigner = CumulativeWindowAssigner.of(Duration.ofMillis(5000), Duration.ofMillis(1000)).withOffset(Duration.ofMillis(100));
assertThat(assigner.assignWindows(ELEMENT, 100L), containsInAnyOrder(timeWindow(100, 1100), timeWindow(100, 2100), timeWindow(100, 3100), timeWindow(100, 4100), timeWindow(100, 5100)));
assertThat(assigner.assignWindows(ELEMENT, 5099L), contains(timeWindow(100, 5100)));
assertThat(assigner.assignWindows(ELEMENT, 5100L), containsInAnyOrder(timeWindow(5100, 6100), timeWindow(5100, 7100), timeWindow(5100, 8100), timeWindow(5100, 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, 2100), new TimeWindow(2100, 3100));
assertEquals(assigner.assignPane(ELEMENT, 5100L), new TimeWindow(5100, 6100));
assertThat(assigner.splitIntoPanes(new TimeWindow(100, 5100)), contains(timeWindow(100, 1100), timeWindow(1100, 2100), timeWindow(2100, 3100), timeWindow(3100, 4100), timeWindow(4100, 5100)));
assertThat(assigner.splitIntoPanes(new TimeWindow(5100, 8100)), contains(timeWindow(5100, 6100), timeWindow(6100, 7100), timeWindow(7100, 8100)));
assertEquals(assigner.getLastWindow(new TimeWindow(4100, 5100)), new TimeWindow(100, 5100));
assertEquals(assigner.getLastWindow(new TimeWindow(2100, 3100)), new TimeWindow(100, 5100));
assertEquals(assigner.getLastWindow(new TimeWindow(7100, 8100)), new TimeWindow(5100, 10100));
}
use of org.apache.flink.table.runtime.operators.window.TimeWindow in project flink by apache.
the class SlidingWindowAssigner method assignWindows.
@Override
public Collection<TimeWindow> assignWindows(RowData element, long timestamp) {
List<TimeWindow> windows = new ArrayList<>((int) (size / slide));
long lastStart = TimeWindow.getWindowStartWithOffset(timestamp, offset, slide);
for (long start = lastStart; start > timestamp - size; start -= slide) {
windows.add(new TimeWindow(start, start + size));
}
return windows;
}
Aggregations