Search in sources :

Example 1 with TimeWindow

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();
}
Also used : RowData(org.apache.flink.table.data.RowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) GenericRowData(org.apache.flink.table.data.GenericRowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) TimeWindow(org.apache.flink.table.runtime.operators.window.TimeWindow)

Example 2 with TimeWindow

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

Example 3 with TimeWindow

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

Example 4 with TimeWindow

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

Example 5 with TimeWindow

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

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