SqlUtils { public static String getDimensionGroupByClause(Multimap<String, String> dimensionValues) { List<String> components = new ArrayList<>(); for (Map.Entry<String, Collection<String>> entry : dimensionValues.asMap().entrySet()) { if (entry.getValue().size() == 1 && "!".equals(entry.getValue().iterator().next())) { components.add(String.format("'%s'", entry.getKey())); } } if (components.isEmpty()) { return null; } return String.format("GROUP BY %s", COMMA.join(components)); }  static String getSql(String metricFunction,
                              String collection,
                              DateTime start,
                              DateTime end,
                              Map<String, String> dimensionValues); static String getSql(String metricFunction,
                              String collection,
                              DateTime start,
                              DateTime end,
                              Multimap<String, String> dimensionValues); static String getBetweenClause(DateTime start, DateTime end); static String getDimensionWhereClause(Multimap<String, String> dimensionValues); static String getDimensionGroupByClause(Multimap<String, String> dimensionValues); static String getDateString(DateTime dateTime);  }
@Test public void testGetGroupByClause() { Multimap<String, String> dimensionValues = ImmutableMultimap.of( "A", "A1", "B", "B1", "C", "!"); String groupByClause = SqlUtils.getDimensionGroupByClause(dimensionValues); Assert.assertEquals(groupByClause, "GROUP BY 'C'"); }