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.");
}
}
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()));
}
}
Aggregations