Source:
private List<FunctionCall> analyzeWindowFunctions(QuerySpecification node, Scope scope, List<Expression> expressions) { for (Expression expression : expressions) { new WindowFunctionValidator().process(expression, analysis); } List<FunctionCall> windowFunctions = extractWindowFunctions(expressions); for (FunctionCall windowFunction : windowFunctions) { if (windowFunction.getFilter().isPresent()) { throw new SemanticException(NOT_SUPPORTED, node, "FILTER is not yet supported for window functions"); } WindowSpecification windowSpecification = resolveWindowSpecification(windowFunction.getWindow().get(), scope::getWindowSpecification); analysis.setWindowSpecification(windowFunction, windowSpecification); ImmutableList.Builder<Node> toExtract = ImmutableList.builder(); toExtract.addAll(windowFunction.getArguments()); toExtract.addAll(windowSpecification.getPartitionBy()); toExtract.addAll(windowSpecification.getOrderBy()); windowSpecification.getFrame().ifPresent(toExtract::add); List<FunctionCall> nestedWindowFunctions = extractWindowFunctions(toExtract.build()); if (!nestedWindowFunctions.isEmpty()) { throw new SemanticException(NESTED_WINDOW, node, "Cannot nest window functions inside window function '%s': %s", windowFunction, windowFunctions); } if (windowFunction.isDistinct()) { throw new SemanticException(NOT_SUPPORTED, node, "DISTINCT in window function parameters not yet supported: %s", windowFunction); } if (windowSpecification.getFrame().isPresent()) { analyzeWindowFrame(windowSpecification.getFrame().get()); } List<TypeSignature> argumentTypes = Lists.transform(windowFunction.getArguments(), expression -> analysis.getType(expression).getTypeSignature()); FunctionKind kind = metadata.getFunctionRegistry().resolveFunction(windowFunction.getName(), fromTypeSignatures(argumentTypes)).getKind(); if (kind != AGGREGATE && kind != WINDOW) { throw new SemanticException(MUST_BE_WINDOW_FUNCTION, node, "Not a window function: %s", windowFunction.getName()); } } return windowFunctions; }

Target:
private List<FunctionCall> analyzeWindowFunctions(QuerySpecification node, Scope scope, List<Expression> expressions) { for (Expression expression : expressions) { new WindowFunctionValidator().process(expression, analysis); } List<FunctionCall> windowFunctions = extractWindowFunctions(expressions); for (FunctionCall windowFunction : windowFunctions) { if (windowFunction.getFilter().isPresent()) { throw new SemanticException(NOT_SUPPORTED, node, "FILTER is not yet supported for window functions"); } WindowSpecification windowSpecification = resolveWindowSpecification(windowFunction.getWindow().get(), scope::getWindowSpecification); analysis.setWindowSpecification(windowFunction, windowSpecification); ImmutableList.Builder<Node> toExtract = ImmutableList.builder(); toExtract.addAll(windowFunction.getArguments()); toExtract.addAll(windowSpecification.getPartitionBy()); toExtract.addAll(windowSpecification.getOrderBy()); windowSpecification.getFrame().ifPresent(toExtract::add); List<FunctionCall> nestedWindowFunctions = extractWindowFunctions(toExtract.build()); if (!nestedWindowFunctions.isEmpty()) { throw new SemanticException(NESTED_WINDOW, node, "Cannot nest window functions inside window function '%s': %s", windowFunction, windowFunctions); } if (windowFunction.isDistinct()) { throw new SemanticException(NOT_SUPPORTED, node, "DISTINCT in window function parameters not yet supported: %s", windowFunction); } windowSpecification.getFrame().ifPresent(this::analyzeWindowFrame); List<TypeSignature> argumentTypes = Lists.transform(windowFunction.getArguments(), expression -> analysis.getType(expression).getTypeSignature()); FunctionKind kind = metadata.getFunctionRegistry().resolveFunction(windowFunction.getName(), fromTypeSignatures(argumentTypes)).getKind(); if (kind != AGGREGATE && kind != WINDOW) { throw new SemanticException(MUST_BE_WINDOW_FUNCTION, node, "Not a window function: %s", windowFunction.getName()); } } return windowFunctions; }