private Aggregate rewriteGBConstantKeys(Aggregate aggregate, ImmutableBitSet fieldsUsed,
      ImmutableBitSet aggCallFields) {
    if ((aggregate.getIndicatorCount() > 0)
        || (aggregate.getGroupSet().isEmpty())
        || fieldsUsed.contains(aggregate.getGroupSet())) {
      return aggregate;
    }

    final RelNode input = aggregate.getInput();

    final RelDataType rowType = input.getRowType();
    RexBuilder rexBuilder = aggregate.getCluster().getRexBuilder();
    final List<RexNode> newProjects = new ArrayList<>();

    final List<RexNode> inputExprs = input instanceof Project ? ((Project) input).getProjects() : null;
    if (inputExprs == null || inputExprs.isEmpty()) {
      return aggregate;
    }

    boolean allConstants = true;
    for (int key : aggregate.getGroupSet()) {
      // getChildExprs on Join could return less number of expressions than there are coming out of join
      if (inputExprs.size() <= key || !isRexLiteral(inputExprs.get(key))) {
        allConstants = false;
        break;
      }
    }

    if (allConstants) {
      for (int i = 0; i < rowType.getFieldCount(); i++) {
        if (aggregate.getGroupSet().get(i) && !aggCallFields.get(i)) {
          newProjects.add(rexBuilder.makeLiteral(true));
        } else {
          newProjects.add(rexBuilder.makeInputRef(input, i));
        }
      }
      final RelBuilder relBuilder = REL_BUILDER.get();
      relBuilder.push(input);
      relBuilder.project(newProjects);
      Aggregate newAggregate = new HiveAggregate(aggregate.getCluster(), aggregate.getTraitSet(), relBuilder.build(),
          aggregate.getGroupSet(), aggregate.getGroupSets(), aggregate.getAggCallList());
      return newAggregate;
    }
    return aggregate;
  }
This method replaces group by 'constant key' with group by true (boolean)
if and only if
 group by doesn't have grouping sets
 all keys in group by are constant
 none of the relnode above aggregate refers to these keys

 If all of above is true then group by is rewritten and a new project is introduced
 underneath aggregate

 This is mainly done so that hive is able to push down queries with
 group by 'constant key with type not supported by druid' into druid.
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveRelFieldTrimmer.java