public AggregateAnalysisResult analyze(
      final ImmutableAnalysis analysis,
      final List<SelectExpression> finalProjection
  ) {
    if (!analysis.getGroupBy().isPresent()) {
      throw new IllegalArgumentException("Not an aggregate query");
    }

    final AggAnalyzer aggAnalyzer = new AggAnalyzer(analysis, functionRegistry);
    aggAnalyzer.process(finalProjection);
    return aggAnalyzer.result();
  }
@Test
  public void shouldThrowOnGroupByAggregateFunction() {
    // Given:
    givenGroupByExpressions(AGG_FUNCTION_CALL);

    // When:
    final KsqlException e = assertThrows(KsqlException.class,
        () -> analyzer.analyze(analysis, selects));

    // Then:
    assertThat(e.getMessage(), containsString(
        "GROUP BY does not support aggregate functions: MAX is an aggregate function."));
  }