private long getGroupingIdValue(List<Integer> list, ImmutableBitSet originalGroupSet, ImmutableBitSet newGroupSet,
          int groupCount) {
    long ind = LongMath.pow(2, groupCount) - 1;
    for (int pos : originalGroupSet) {
      ind &= ~(1L << groupCount - newGroupSet.indexOf(pos) - 1);
    }
    for (int i : list) {
      ind &= ~(1L << groupCount - newGroupSet.indexOf(i) - 1);
    }
    return ind;
  }
Converts an aggregate relational expression that contains only
count(distinct) to grouping sets with count. For example select
count(distinct department_id), count(distinct gender), count(distinct
education_level) from employee; can be transformed to
select
count(case when i=1 and department_id is not null then 1 else null end) as c0,
count(case when i=2 and gender is not null then 1 else null end) as c1,
count(case when i=4 and education_level is not null then 1 else null end) as c2
from (select
grouping__id as i, department_id, gender, education_level from employee
group by department_id, gender, education_level grouping sets
(department_id, gender, education_level))subq;
@throws CalciteSemanticException
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveExpandDistinctAggregatesRule.java