@Test public void testComputeColumnAggregations() { String columnName = "col"; int value = 5; TableAnswerElement table = new TableAnswerElement( new TableMetadata( ImmutableList.of(new ColumnMetadata(columnName, Schema.INTEGER, "foobar")), new DisplayHints().getTextDesc())) .addRow(Row.of(columnName, value)); List<ColumnAggregation> aggregations = ImmutableList.of(new ColumnAggregation(Aggregation.MAX, columnName)); assertThat( AnswerMetadataUtil.computeColumnAggregations(table, aggregations, _logger), equalTo(ImmutableMap.of(columnName, ImmutableMap.of(Aggregation.MAX, value)))); }
@VisibleForTesting @Nonnull static Map<String, Map<Aggregation, Object>> computeColumnAggregations( @Nonnull TableAnswerElement table, @Nonnull List<ColumnAggregation> aggregations, @Nonnull BatfishLogger logger) { Map<String, Map<Aggregation, Object>> columnAggregations = new HashMap<>(); aggregations.stream() .map(columnAggregation -> computeColumnAggregation(table, columnAggregation, logger)) .filter(Objects::nonNull) .forEach( columnAggregationResult -> columnAggregations .computeIfAbsent(columnAggregationResult.getColumn(), c -> new HashMap<>()) .computeIfAbsent( columnAggregationResult.getAggregation(), a -> columnAggregationResult.getValue())); return CollectionUtil.toImmutableMap( columnAggregations, Entry::getKey, columnAggregationsByColumnEntry -> CollectionUtil.toImmutableMap( columnAggregationsByColumnEntry.getValue(), Entry::getKey, Entry::getValue)); }
AnswerMetadataUtil { @VisibleForTesting @Nonnull static Map<String, Map<Aggregation, Object>> computeColumnAggregations( @Nonnull TableAnswerElement table, @Nonnull List<ColumnAggregation> aggregations, @Nonnull BatfishLogger logger) { Map<String, Map<Aggregation, Object>> columnAggregations = new HashMap<>(); aggregations.stream() .map(columnAggregation -> computeColumnAggregation(table, columnAggregation, logger)) .filter(Objects::nonNull) .forEach( columnAggregationResult -> columnAggregations .computeIfAbsent(columnAggregationResult.getColumn(), c -> new HashMap<>()) .computeIfAbsent( columnAggregationResult.getAggregation(), a -> columnAggregationResult.getValue())); return CollectionUtil.toImmutableMap( columnAggregations, Entry::getKey, columnAggregationsByColumnEntry -> CollectionUtil.toImmutableMap( columnAggregationsByColumnEntry.getValue(), Entry::getKey, Entry::getValue)); } }
AnswerMetadataUtil { @VisibleForTesting @Nonnull static Map<String, Map<Aggregation, Object>> computeColumnAggregations( @Nonnull TableAnswerElement table, @Nonnull List<ColumnAggregation> aggregations, @Nonnull BatfishLogger logger) { Map<String, Map<Aggregation, Object>> columnAggregations = new HashMap<>(); aggregations.stream() .map(columnAggregation -> computeColumnAggregation(table, columnAggregation, logger)) .filter(Objects::nonNull) .forEach( columnAggregationResult -> columnAggregations .computeIfAbsent(columnAggregationResult.getColumn(), c -> new HashMap<>()) .computeIfAbsent( columnAggregationResult.getAggregation(), a -> columnAggregationResult.getValue())); return CollectionUtil.toImmutableMap( columnAggregations, Entry::getKey, columnAggregationsByColumnEntry -> CollectionUtil.toImmutableMap( columnAggregationsByColumnEntry.getValue(), Entry::getKey, Entry::getValue)); } private  AnswerMetadataUtil(); }
AnswerMetadataUtil { @VisibleForTesting @Nonnull static Map<String, Map<Aggregation, Object>> computeColumnAggregations( @Nonnull TableAnswerElement table, @Nonnull List<ColumnAggregation> aggregations, @Nonnull BatfishLogger logger) { Map<String, Map<Aggregation, Object>> columnAggregations = new HashMap<>(); aggregations.stream() .map(columnAggregation -> computeColumnAggregation(table, columnAggregation, logger)) .filter(Objects::nonNull) .forEach( columnAggregationResult -> columnAggregations .computeIfAbsent(columnAggregationResult.getColumn(), c -> new HashMap<>()) .computeIfAbsent( columnAggregationResult.getAggregation(), a -> columnAggregationResult.getValue())); return CollectionUtil.toImmutableMap( columnAggregations, Entry::getKey, columnAggregationsByColumnEntry -> CollectionUtil.toImmutableMap( columnAggregationsByColumnEntry.getValue(), Entry::getKey, Entry::getValue)); } private  AnswerMetadataUtil(); static @Nonnull AnswerMetadata computeAnswerMetadata(
      @Nonnull Answer answer, @Nonnull BatfishLogger logger); }
AnswerMetadataUtil { @VisibleForTesting @Nonnull static Map<String, Map<Aggregation, Object>> computeColumnAggregations( @Nonnull TableAnswerElement table, @Nonnull List<ColumnAggregation> aggregations, @Nonnull BatfishLogger logger) { Map<String, Map<Aggregation, Object>> columnAggregations = new HashMap<>(); aggregations.stream() .map(columnAggregation -> computeColumnAggregation(table, columnAggregation, logger)) .filter(Objects::nonNull) .forEach( columnAggregationResult -> columnAggregations .computeIfAbsent(columnAggregationResult.getColumn(), c -> new HashMap<>()) .computeIfAbsent( columnAggregationResult.getAggregation(), a -> columnAggregationResult.getValue())); return CollectionUtil.toImmutableMap( columnAggregations, Entry::getKey, columnAggregationsByColumnEntry -> CollectionUtil.toImmutableMap( columnAggregationsByColumnEntry.getValue(), Entry::getKey, Entry::getValue)); } private  AnswerMetadataUtil(); static @Nonnull AnswerMetadata computeAnswerMetadata(
      @Nonnull Answer answer, @Nonnull BatfishLogger logger);  }