Search in sources :

Example 1 with WindowSpec

use of org.apache.flink.table.planner.plan.logical.WindowSpec in project flink by apache.

the class StreamExecWindowAggregateBase method createSliceAssigner.

// ------------------------------------------------------------------------------------------
// Utilities
// ------------------------------------------------------------------------------------------
protected SliceAssigner createSliceAssigner(WindowingStrategy windowingStrategy, ZoneId shiftTimeZone) {
    WindowSpec windowSpec = windowingStrategy.getWindow();
    if (windowingStrategy instanceof WindowAttachedWindowingStrategy) {
        int windowEndIndex = ((WindowAttachedWindowingStrategy) windowingStrategy).getWindowEnd();
        // we don't need time attribute to assign windows, use a magic value in this case
        SliceAssigner innerAssigner = createSliceAssigner(windowSpec, Integer.MAX_VALUE, shiftTimeZone);
        return SliceAssigners.windowed(windowEndIndex, innerAssigner);
    } else if (windowingStrategy instanceof SliceAttachedWindowingStrategy) {
        int sliceEndIndex = ((SliceAttachedWindowingStrategy) windowingStrategy).getSliceEnd();
        // we don't need time attribute to assign windows, use a magic value in this case
        SliceAssigner innerAssigner = createSliceAssigner(windowSpec, Integer.MAX_VALUE, shiftTimeZone);
        return SliceAssigners.sliced(sliceEndIndex, innerAssigner);
    } else if (windowingStrategy instanceof TimeAttributeWindowingStrategy) {
        final int timeAttributeIndex;
        if (windowingStrategy.isRowtime()) {
            timeAttributeIndex = ((TimeAttributeWindowingStrategy) windowingStrategy).getTimeAttributeIndex();
        } else {
            timeAttributeIndex = -1;
        }
        return createSliceAssigner(windowSpec, timeAttributeIndex, shiftTimeZone);
    } else {
        throw new UnsupportedOperationException(windowingStrategy + " is not supported yet.");
    }
}
Also used : SliceAssigner(org.apache.flink.table.runtime.operators.window.slicing.SliceAssigner) TimeAttributeWindowingStrategy(org.apache.flink.table.planner.plan.logical.TimeAttributeWindowingStrategy) WindowAttachedWindowingStrategy(org.apache.flink.table.planner.plan.logical.WindowAttachedWindowingStrategy) SliceAttachedWindowingStrategy(org.apache.flink.table.planner.plan.logical.SliceAttachedWindowingStrategy) 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)

Example 2 with WindowSpec

use of org.apache.flink.table.planner.plan.logical.WindowSpec 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)

Aggregations

CumulativeWindowSpec (org.apache.flink.table.planner.plan.logical.CumulativeWindowSpec)2 HoppingWindowSpec (org.apache.flink.table.planner.plan.logical.HoppingWindowSpec)2 TumblingWindowSpec (org.apache.flink.table.planner.plan.logical.TumblingWindowSpec)2 WindowSpec (org.apache.flink.table.planner.plan.logical.WindowSpec)2 TableException (org.apache.flink.table.api.TableException)1 SliceAttachedWindowingStrategy (org.apache.flink.table.planner.plan.logical.SliceAttachedWindowingStrategy)1 TimeAttributeWindowingStrategy (org.apache.flink.table.planner.plan.logical.TimeAttributeWindowingStrategy)1 WindowAttachedWindowingStrategy (org.apache.flink.table.planner.plan.logical.WindowAttachedWindowingStrategy)1 CumulativeWindowAssigner (org.apache.flink.table.runtime.operators.window.assigners.CumulativeWindowAssigner)1 SlidingWindowAssigner (org.apache.flink.table.runtime.operators.window.assigners.SlidingWindowAssigner)1 TumblingWindowAssigner (org.apache.flink.table.runtime.operators.window.assigners.TumblingWindowAssigner)1 SliceAssigner (org.apache.flink.table.runtime.operators.window.slicing.SliceAssigner)1