private RelNode convert(Aggregate aggregate, List<List<Integer>> argList, ImmutableBitSet newGroupSet)
      throws CalciteSemanticException {
    // we use this map to map the position of argList to the position of grouping set
    Map<Integer, Integer> map = new HashMap<>();
    List<List<Integer>> cleanArgList = new ArrayList<>();
    final Aggregate groupingSets = createGroupingSets(aggregate, argList, cleanArgList, map, newGroupSet);
    return createCount(groupingSets, argList, cleanArgList, map, aggregate.getGroupSet(), newGroupSet);
  }
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