Search in sources :

Example 1 with SlidingWindowAssigner

use of org.apache.flink.table.runtime.operators.window.assigners.SlidingWindowAssigner in project flink by apache.

the class StreamArrowPythonGroupWindowAggregateFunctionOperatorTest method getTestOperator.

@Override
public AbstractArrowPythonAggregateFunctionOperator getTestOperator(Configuration config, PythonFunctionInfo[] pandasAggregateFunctions, RowType inputType, RowType outputType, int[] groupingSet, int[] udafInputOffsets) {
    long size = 10000L;
    long slide = 5000L;
    SlidingWindowAssigner windowAssigner = SlidingWindowAssigner.of(Duration.ofMillis(size), Duration.ofMillis(slide)).withEventTime();
    EventTimeTriggers.AfterEndOfWindow<Window> trigger = EventTimeTriggers.afterEndOfWindow();
    RowType udfInputType = (RowType) Projection.of(udafInputOffsets).project(inputType);
    RowType udfOutputType = (RowType) Projection.range(groupingSet.length, outputType.getFieldCount() - 2).project(outputType);
    return new PassThroughStreamArrowPythonGroupWindowAggregateFunctionOperator(config, pandasAggregateFunctions, inputType, udfInputType, udfOutputType, 3, windowAssigner, trigger, 0, new NamedWindowProperty[] { new NamedWindowProperty("start", new WindowStart(null)), new NamedWindowProperty("end", new WindowEnd(null)) }, UTC_ZONE_ID, ProjectionCodeGenerator.generateProjection(CodeGeneratorContext.apply(new TableConfig()), "UdafInputProjection", inputType, udfInputType, udafInputOffsets));
}
Also used : Window(org.apache.flink.table.runtime.operators.window.Window) NamedWindowProperty(org.apache.flink.table.runtime.groupwindow.NamedWindowProperty) SlidingWindowAssigner(org.apache.flink.table.runtime.operators.window.assigners.SlidingWindowAssigner) WindowStart(org.apache.flink.table.runtime.groupwindow.WindowStart) RowType(org.apache.flink.table.types.logical.RowType) WindowEnd(org.apache.flink.table.runtime.groupwindow.WindowEnd) TableConfig(org.apache.flink.table.api.TableConfig) EventTimeTriggers(org.apache.flink.table.runtime.operators.window.triggers.EventTimeTriggers)

Example 2 with SlidingWindowAssigner

use of org.apache.flink.table.runtime.operators.window.assigners.SlidingWindowAssigner in project flink by apache.

the class PythonStreamGroupWindowAggregateOperatorTest method getTestOperator.

@Override
OneInputStreamOperator getTestOperator(Configuration config) {
    long size = 10000L;
    long slide = 5000L;
    SlidingWindowAssigner windowAssigner = SlidingWindowAssigner.of(Duration.ofMillis(size), Duration.ofMillis(slide)).withEventTime();
    WindowReference windowRef = new WindowReference("w$", new TimestampType(3));
    return new PassThroughPythonStreamGroupWindowAggregateOperator(config, getInputType(), getOutputType(), new PythonAggregateFunctionInfo[] { new PythonAggregateFunctionInfo(PythonScalarFunctionOperatorTestBase.DummyPythonFunction.INSTANCE, new Integer[] { 2 }, -1, false) }, getGrouping(), -1, false, false, 3, windowAssigner, FlinkFnApi.GroupWindow.WindowType.SLIDING_GROUP_WINDOW, true, true, size, slide, 0L, 0L, new NamedWindowProperty[] { new NamedWindowProperty("start", new WindowStart(null)), new NamedWindowProperty("end", new WindowEnd(null)) }, UTC_ZONE_ID);
}
Also used : NamedWindowProperty(org.apache.flink.table.runtime.groupwindow.NamedWindowProperty) SlidingWindowAssigner(org.apache.flink.table.runtime.operators.window.assigners.SlidingWindowAssigner) PythonAggregateFunctionInfo(org.apache.flink.table.functions.python.PythonAggregateFunctionInfo) WindowStart(org.apache.flink.table.runtime.groupwindow.WindowStart) TimestampType(org.apache.flink.table.types.logical.TimestampType) WindowEnd(org.apache.flink.table.runtime.groupwindow.WindowEnd) WindowReference(org.apache.flink.table.runtime.groupwindow.WindowReference)

Example 3 with SlidingWindowAssigner

use of org.apache.flink.table.runtime.operators.window.assigners.SlidingWindowAssigner in project flink by apache.

the class WindowTableFunctionUtil method createWindowAssigner.

/**
 * Creates window assigner based on input window strategy.
 *
 * @param windowingStrategy input window strategy
 * @return new created window assigner
 */
public static WindowAssigner<TimeWindow> createWindowAssigner(TimeAttributeWindowingStrategy windowingStrategy) {
    WindowSpec windowSpec = windowingStrategy.getWindow();
    boolean isProctime = windowingStrategy.isProctime();
    if (windowSpec instanceof TumblingWindowSpec) {
        TumblingWindowSpec tumblingWindowSpec = (TumblingWindowSpec) windowSpec;
        TumblingWindowAssigner windowAssigner = TumblingWindowAssigner.of(tumblingWindowSpec.getSize());
        if (isProctime) {
            windowAssigner = windowAssigner.withProcessingTime();
        }
        if (tumblingWindowSpec.getOffset() != null) {
            windowAssigner = windowAssigner.withOffset(tumblingWindowSpec.getOffset());
        }
        return windowAssigner;
    } else if (windowSpec instanceof HoppingWindowSpec) {
        HoppingWindowSpec hoppingWindowSpec = (HoppingWindowSpec) windowSpec;
        SlidingWindowAssigner windowAssigner = SlidingWindowAssigner.of(hoppingWindowSpec.getSize(), hoppingWindowSpec.getSlide());
        if (isProctime) {
            windowAssigner = windowAssigner.withProcessingTime();
        }
        if (hoppingWindowSpec.getOffset() != null) {
            windowAssigner = windowAssigner.withOffset(hoppingWindowSpec.getOffset());
        }
        return windowAssigner;
    } else if (windowSpec instanceof CumulativeWindowSpec) {
        CumulativeWindowSpec cumulativeWindowSpec = (CumulativeWindowSpec) windowSpec;
        CumulativeWindowAssigner windowAssigner = CumulativeWindowAssigner.of(cumulativeWindowSpec.getMaxSize(), cumulativeWindowSpec.getStep());
        if (isProctime) {
            windowAssigner = windowAssigner.withProcessingTime();
        }
        if (cumulativeWindowSpec.getOffset() != null) {
            windowAssigner = windowAssigner.withOffset(cumulativeWindowSpec.getOffset());
        }
        return windowAssigner;
    } else {
        throw new TableException(String.format("Unknown window spec: %s", windowSpec.getClass().getSimpleName()));
    }
}
Also used : SlidingWindowAssigner(org.apache.flink.table.runtime.operators.window.assigners.SlidingWindowAssigner) TableException(org.apache.flink.table.api.TableException) CumulativeWindowSpec(org.apache.flink.table.planner.plan.logical.CumulativeWindowSpec) CumulativeWindowAssigner(org.apache.flink.table.runtime.operators.window.assigners.CumulativeWindowAssigner) TumblingWindowAssigner(org.apache.flink.table.runtime.operators.window.assigners.TumblingWindowAssigner) TumblingWindowSpec(org.apache.flink.table.planner.plan.logical.TumblingWindowSpec) WindowSpec(org.apache.flink.table.planner.plan.logical.WindowSpec) HoppingWindowSpec(org.apache.flink.table.planner.plan.logical.HoppingWindowSpec) CumulativeWindowSpec(org.apache.flink.table.planner.plan.logical.CumulativeWindowSpec) HoppingWindowSpec(org.apache.flink.table.planner.plan.logical.HoppingWindowSpec) TumblingWindowSpec(org.apache.flink.table.planner.plan.logical.TumblingWindowSpec)

Example 4 with SlidingWindowAssigner

use of org.apache.flink.table.runtime.operators.window.assigners.SlidingWindowAssigner in project flink by apache.

the class WindowTableFunctionOperatorTest method testHopWindows.

@Test
public void testHopWindows() throws Exception {
    final SlidingWindowAssigner assigner = SlidingWindowAssigner.of(Duration.ofSeconds(3), Duration.ofSeconds(1));
    OneInputStreamOperatorTestHarness<RowData, RowData> testHarness = createTestHarness(assigner, shiftTimeZone);
    testHarness.setup(OUT_SERIALIZER);
    testHarness.open();
    // process elements
    ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>();
    testHarness.processElement(insertRecord("key1", 1, 20L));
    testHarness.processElement(insertRecord("key2", 1, 3999L));
    testHarness.processWatermark(new Watermark(999));
    // append 3 fields: window_start, window_end, window_time
    expectedOutput.add(insertRecord("key1", 1, 20L, localMills(-2000L), localMills(1000L), 999L));
    expectedOutput.add(insertRecord("key1", 1, 20L, localMills(-1000L), localMills(2000L), 1999L));
    expectedOutput.add(insertRecord("key1", 1, 20L, localMills(0L), localMills(3000L), 2999L));
    expectedOutput.add(insertRecord("key2", 1, 3999L, localMills(1000L), localMills(4000L), 3999L));
    expectedOutput.add(insertRecord("key2", 1, 3999L, localMills(2000L), localMills(5000L), 4999L));
    expectedOutput.add(insertRecord("key2", 1, 3999L, localMills(3000L), localMills(6000L), 5999L));
    expectedOutput.add(new Watermark(999));
    ASSERTER.assertOutputEqualsSorted("Output was not correct.", expectedOutput, testHarness.getOutput());
    // late element would not be dropped
    testHarness.processElement(insertRecord("key2", 1, 80L));
    expectedOutput.add(insertRecord("key2", 1, 80L, localMills(-2000L), localMills(1000L), 999L));
    expectedOutput.add(insertRecord("key2", 1, 80L, localMills(-1000L), localMills(2000L), 1999L));
    expectedOutput.add(insertRecord("key2", 1, 80L, localMills(0L), localMills(3000L), 2999L));
    ASSERTER.assertOutputEqualsSorted("Output was not correct.", expectedOutput, testHarness.getOutput());
}
Also used : SlidingWindowAssigner(org.apache.flink.table.runtime.operators.window.assigners.SlidingWindowAssigner) RowData(org.apache.flink.table.data.RowData) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Watermark(org.apache.flink.streaming.api.watermark.Watermark) Test(org.junit.Test)

Example 5 with SlidingWindowAssigner

use of org.apache.flink.table.runtime.operators.window.assigners.SlidingWindowAssigner in project flink by apache.

the class WindowTableFunctionOperatorTest method testProcessingTimeHopWindows.

@Test
public void testProcessingTimeHopWindows() throws Exception {
    final SlidingWindowAssigner assigner = SlidingWindowAssigner.of(Duration.ofSeconds(3), Duration.ofSeconds(1)).withProcessingTime();
    OneInputStreamOperatorTestHarness<RowData, RowData> testHarness = createTestHarness(assigner, shiftTimeZone);
    testHarness.setup(OUT_SERIALIZER);
    testHarness.open();
    // process elements
    ConcurrentLinkedQueue<Object> expectedOutput = new ConcurrentLinkedQueue<>();
    // timestamp is ignored in processing time
    testHarness.setProcessingTime(20L);
    testHarness.processElement(insertRecord("key1", 1, Long.MAX_VALUE));
    testHarness.setProcessingTime(3999L);
    testHarness.processElement(insertRecord("key2", 1, Long.MAX_VALUE));
    // append 3 fields: window_start, window_end, window_time
    expectedOutput.add(insertRecord("key1", 1, Long.MAX_VALUE, localMills(-2000L), localMills(1000L), 999L));
    expectedOutput.add(insertRecord("key1", 1, Long.MAX_VALUE, localMills(-1000L), localMills(2000L), 1999L));
    expectedOutput.add(insertRecord("key1", 1, Long.MAX_VALUE, localMills(0L), localMills(3000L), 2999L));
    expectedOutput.add(insertRecord("key2", 1, Long.MAX_VALUE, localMills(1000L), localMills(4000L), 3999L));
    expectedOutput.add(insertRecord("key2", 1, Long.MAX_VALUE, localMills(2000L), localMills(5000L), 4999L));
    expectedOutput.add(insertRecord("key2", 1, Long.MAX_VALUE, localMills(3000L), localMills(6000L), 5999L));
    ASSERTER.assertOutputEqualsSorted("Output was not correct.", expectedOutput, testHarness.getOutput());
}
Also used : SlidingWindowAssigner(org.apache.flink.table.runtime.operators.window.assigners.SlidingWindowAssigner) RowData(org.apache.flink.table.data.RowData) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Test(org.junit.Test)

Aggregations

SlidingWindowAssigner (org.apache.flink.table.runtime.operators.window.assigners.SlidingWindowAssigner)5 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2 RowData (org.apache.flink.table.data.RowData)2 NamedWindowProperty (org.apache.flink.table.runtime.groupwindow.NamedWindowProperty)2 WindowEnd (org.apache.flink.table.runtime.groupwindow.WindowEnd)2 WindowStart (org.apache.flink.table.runtime.groupwindow.WindowStart)2 Test (org.junit.Test)2 Watermark (org.apache.flink.streaming.api.watermark.Watermark)1 TableConfig (org.apache.flink.table.api.TableConfig)1 TableException (org.apache.flink.table.api.TableException)1 PythonAggregateFunctionInfo (org.apache.flink.table.functions.python.PythonAggregateFunctionInfo)1 CumulativeWindowSpec (org.apache.flink.table.planner.plan.logical.CumulativeWindowSpec)1 HoppingWindowSpec (org.apache.flink.table.planner.plan.logical.HoppingWindowSpec)1 TumblingWindowSpec (org.apache.flink.table.planner.plan.logical.TumblingWindowSpec)1 WindowSpec (org.apache.flink.table.planner.plan.logical.WindowSpec)1 WindowReference (org.apache.flink.table.runtime.groupwindow.WindowReference)1 Window (org.apache.flink.table.runtime.operators.window.Window)1 CumulativeWindowAssigner (org.apache.flink.table.runtime.operators.window.assigners.CumulativeWindowAssigner)1 TumblingWindowAssigner (org.apache.flink.table.runtime.operators.window.assigners.TumblingWindowAssigner)1 EventTimeTriggers (org.apache.flink.table.runtime.operators.window.triggers.EventTimeTriggers)1