### Question:
GroupingOperationRewriter { static long calculateGrouping(Set<Integer> groupingSet, List<Integer> columns) { long grouping = (1L << columns.size()) - 1; for (int index = 0; index < columns.size(); index++) { int column = columns.get(index); if (groupingSet.contains(column)) { grouping = grouping & ~(1L << (columns.size() - 1 - index)); } } return grouping; } private  GroupingOperationRewriter(); static Expression rewriteGroupingOperation(GroupingOperation expression, List<Set<Integer>> groupingSets, Map<NodeRef<Expression>, ResolvedField> columnReferenceFields, Optional<Symbol> groupIdSymbol);  }### Answer:
@Test public void testGroupingOperationAllBitsSet() { List<Integer> groupingOrdinals = ImmutableList.of(0, 4, 8); List<Set<Integer>> groupingSetOrdinals = ImmutableList.of(ImmutableSet.of(1), ImmutableSet.of(7, 3, 1), ImmutableSet.of(9, 1)); for (Set<Integer> groupingSet : groupingSetOrdinals) { assertEquals(calculateGrouping(groupingSet, groupingOrdinals), 7L); } }
@Test public void testGroupingOperationNoBitsSet() { List<Integer> groupingOrdinals = ImmutableList.of(4, 6); List<Set<Integer>> groupingSetOrdinals = ImmutableList.of(ImmutableSet.of(4, 6)); for (Set<Integer> groupingSet : groupingSetOrdinals) { assertEquals(calculateGrouping(groupingSet, groupingOrdinals), 0L); } }
@Test public void testGroupingOperationSomeBitsSet() { List<Integer> groupingOrdinals = ImmutableList.of(7, 2, 9, 3, 5); List<Set<Integer>> groupingSetOrdinals = ImmutableList.of(ImmutableSet.of(4, 2), ImmutableSet.of(9, 7, 14), ImmutableSet.of(5, 2, 7), ImmutableSet.of(3)); List<Long> expectedResults = ImmutableList.of(23L, 11L, 6L, 29L); for (int groupId = 0; groupId < groupingSetOrdinals.size(); groupId++) { Set<Integer> groupingSet = groupingSetOrdinals.get(groupId); assertEquals(Long.valueOf(calculateGrouping(groupingSet, groupingOrdinals)), expectedResults.get(groupId)); } }
@Test public void testMoreThanThirtyTwoArguments() { List<Set<Integer>> groupingSetOrdinals = ImmutableList.of(ImmutableSet.of(20, 2, 13, 33, 40, 9, 14), ImmutableSet.of(28, 4, 5, 29, 31, 10)); List<Long> expectedResults = ImmutableList.of(822283861886L, 995358664191L); for (int groupId = 0; groupId < groupingSetOrdinals.size(); groupId++) { Set<Integer> groupingSet = groupingSetOrdinals.get(groupId); assertEquals(Long.valueOf(calculateGrouping(groupingSet, fortyIntegers)), expectedResults.get(groupId)); } }