in flink-connector-hive/src/main/java/org/apache/flink/table/planner/delegation/hive/copy/HiveParserWindowingSpec.java [90:131]
private void setAndValidateOrderSpec(WindowFunctionSpec wFn) throws SemanticException {
WindowSpec wdwSpec = wFn.getWindowSpec();
wdwSpec.ensureOrderSpec(wFn);
WindowFrameSpec wFrame = wdwSpec.getWindowFrame();
OrderSpec order = wdwSpec.getOrder();
BoundarySpec start = wFrame.getStart();
BoundarySpec end = wFrame.getEnd();
if (wFrame.getWindowType() == WindowType.RANGE) {
if (order == null || order.getExpressions().size() == 0) {
throw new SemanticException(
"Range based Window Frame needs to specify ORDER BY clause");
}
boolean currentRange =
start.getDirection() == Direction.CURRENT
&& end.getDirection() == Direction.CURRENT;
boolean defaultPreceding =
start.getDirection() == Direction.PRECEDING
&& start.getAmt() == BoundarySpec.UNBOUNDED_AMOUNT
&& end.getDirection() == Direction.CURRENT;
boolean defaultFollowing =
start.getDirection() == Direction.CURRENT
&& end.getDirection() == Direction.FOLLOWING
&& end.getAmt() == BoundarySpec.UNBOUNDED_AMOUNT;
boolean defaultPrecedingFollowing =
start.getDirection() == Direction.PRECEDING
&& start.getAmt() == BoundarySpec.UNBOUNDED_AMOUNT
&& end.getDirection() == Direction.FOLLOWING
&& end.getAmt() == BoundarySpec.UNBOUNDED_AMOUNT;
boolean multiOrderAllowed =
currentRange
|| defaultPreceding
|| defaultFollowing
|| defaultPrecedingFollowing;
if (order.getExpressions().size() != 1 && !multiOrderAllowed) {
throw new SemanticException(
"Range value based Window Frame can have only 1 Sort Key");
}
}
}