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 shouldCaptureHavingNonAggregateFunctionArgumentsAsRequired() {
    // Given:
    when(analysis.getHavingExpression()).thenReturn(Optional.of(
        new FunctionCall(FunctionName.of("MAX"),
            ImmutableList.of(COL2))
    ));

    // When:
    final AggregateAnalysisResult result = analyzer
        .analyze(analysis, selects);

    // Then:
    assertThat(result.getRequiredColumns(), hasItem(COL2));
  }