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.isBounded()
          && end.getDirection() == Direction.CURRENT;
      boolean defaultFollowing = start.getDirection() == Direction.CURRENT
          && end.getDirection() == Direction.FOLLOWING && !end.isBounded();
      boolean defaultPrecedingFollowing = start.getDirection() == Direction.PRECEDING
          && !start.isBounded() && end.getDirection() == Direction.FOLLOWING && !end.isBounded();
      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");
      }
    }
  }
Add default order spec if there is no order and validate order spec for valued based
windowing since only one sort key is allowed.
@param wFn Window function spec
@throws SemanticException
ql/src/java/org/apache/hadoop/hive/ql/parse/WindowingSpec.java