use of org.apache.flink.table.planner.plan.logical.CumulativeWindowSpec 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()));
}
}
use of org.apache.flink.table.planner.plan.logical.CumulativeWindowSpec in project flink by apache.
the class StreamExecWindowAggregateBase method createSliceAssigner.
protected SliceAssigner createSliceAssigner(WindowSpec windowSpec, int timeAttributeIndex, ZoneId shiftTimeZone) {
if (windowSpec instanceof TumblingWindowSpec) {
Duration size = ((TumblingWindowSpec) windowSpec).getSize();
SliceAssigners.TumblingSliceAssigner assigner = SliceAssigners.tumbling(timeAttributeIndex, shiftTimeZone, size);
Duration offset = ((TumblingWindowSpec) windowSpec).getOffset();
if (offset != null) {
assigner = assigner.withOffset(offset);
}
return assigner;
} else if (windowSpec instanceof HoppingWindowSpec) {
Duration size = ((HoppingWindowSpec) windowSpec).getSize();
Duration slide = ((HoppingWindowSpec) windowSpec).getSlide();
if (size.toMillis() % slide.toMillis() != 0) {
throw new TableException(String.format("HOP table function based aggregate requires size must be an " + "integral multiple of slide, but got size %s ms and slide %s ms", size.toMillis(), slide.toMillis()));
}
SliceAssigners.HoppingSliceAssigner assigner = SliceAssigners.hopping(timeAttributeIndex, shiftTimeZone, size, slide);
Duration offset = ((HoppingWindowSpec) windowSpec).getOffset();
if (offset != null) {
assigner = assigner.withOffset(offset);
}
return assigner;
} else if (windowSpec instanceof CumulativeWindowSpec) {
Duration maxSize = ((CumulativeWindowSpec) windowSpec).getMaxSize();
Duration step = ((CumulativeWindowSpec) windowSpec).getStep();
if (maxSize.toMillis() % step.toMillis() != 0) {
throw new TableException(String.format("CUMULATE table function based aggregate requires maxSize must be an " + "integral multiple of step, but got maxSize %s ms and step %s ms", maxSize.toMillis(), step.toMillis()));
}
SliceAssigners.CumulativeSliceAssigner assigner = SliceAssigners.cumulative(timeAttributeIndex, shiftTimeZone, maxSize, step);
Duration offset = ((CumulativeWindowSpec) windowSpec).getOffset();
if (offset != null) {
assigner = assigner.withOffset(offset);
}
return assigner;
} else {
throw new UnsupportedOperationException(windowSpec + " is not supported yet.");
}
}
Aggregations