@UdafFactory(description = "Build a value-to-count histogram of input Strings")
  public static TableUdaf<String, Map<String, Long>, Map<String, Long>> histogramString() {
    return histogram();
  }
@Test
  public void shouldMergeCountsIncludingNulls() {
    final TableUdaf<String, Map<String, Long>, Map<String, Long>> udaf = HistogramUdaf.histogramString();

    Map<String, Long> lhs = udaf.initialize();
    final Integer[] leftValues = new Integer[] {1, 2, 1, 4};
    for (final Integer thisValue : leftValues) {
      lhs = udaf.aggregate(String.valueOf(thisValue), lhs);
    }
    lhs = udaf.aggregate(null, lhs);
    assertThat(lhs.entrySet(), hasSize(4));
    assertThat(lhs, hasEntry("1", 2L));
    assertThat(lhs, hasEntry("2", 1L));
    assertThat(lhs, hasEntry("4", 1L));
    assertThat(lhs, hasEntry(null, 1L));

    Map<String, Long> rhs = udaf.initialize();
    final Integer[] rightValues = new Integer[] {1, 3};
    for (final Integer thisValue : rightValues) {
      rhs = udaf.aggregate(String.valueOf(thisValue), rhs);
    }
    rhs = udaf.aggregate(null, rhs);
    rhs = udaf.aggregate(null, rhs);
    assertThat(rhs.entrySet(), hasSize(3));
    assertThat(rhs, hasEntry("1", 1L));
    assertThat(rhs, hasEntry("3", 1L));
    assertThat(rhs, hasEntry(null, 2L));

    final Map<String, Long> merged = udaf.merge(lhs, rhs);
    assertThat(merged.entrySet(), hasSize(5));
    assertThat(merged, hasEntry("1", 3L));
    assertThat(merged, hasEntry("2", 1L));
    assertThat(merged, hasEntry("3", 1L));
    assertThat(merged, hasEntry("4", 1L));
    assertThat(merged, hasEntry(null, 3L));
  }