private AggregateCall convertGBAgg(AggregateInfo agg, List<RexNode> gbChildProjLst,
        HashMap<String, Integer> rexNodeToPosMap, Integer childProjLstIndx) {
      // 1. Get agg fn ret type in Calcite
      RelDataType aggFnRetType = TypeConverter.convert(agg.getReturnType(),
          this.cluster.getTypeFactory());

      // 2. Convert Agg Fn args and type of args to Calcite
      List<Integer> argList = new ArrayList<>();
      ImmutableList.Builder<RelDataType> aggArgRelDTBldr = ImmutableList.builder();
      for (RexNode rexNd : agg.getParameters()) {
        Integer inputIndx = rexNodeToPosMap.get(rexNd.toString());
        if (inputIndx == null) {
          gbChildProjLst.add(rexNd);
          rexNodeToPosMap.put(rexNd.toString(), childProjLstIndx);
          inputIndx = childProjLstIndx;
          childProjLstIndx++;
        }
        argList.add(inputIndx);

        aggArgRelDTBldr.add(rexNd.getType());
      }

      // 3. Get Aggregation FN from Calcite given name, ret type and input arg
      // type
      final SqlAggFunction aggregation = SqlFunctionConverter.getCalciteAggFn(agg.getAggregateName(), agg.isDistinct(),
          aggArgRelDTBldr.build(), aggFnRetType);

      List<RelFieldCollation> collationList = new ArrayList<>(agg.getCollation().size());
      for (FunctionHelper.FieldCollation fieldCollation : agg.getCollation()) {
        Integer inputIndx = rexNodeToPosMap.get(fieldCollation.getSortExpression().toString());
        if (inputIndx == null) {
          gbChildProjLst.add(fieldCollation.getSortExpression());
          rexNodeToPosMap.put(fieldCollation.getSortExpression().toString(), childProjLstIndx);
          inputIndx = childProjLstIndx;
          childProjLstIndx++;
        }

        collationList.add(new RelFieldCollation(inputIndx,
                DirectionUtils.codeToDirection(fieldCollation.getSortDirection()),
                fieldCollation.getNullOrdering().getDirection()));
      }

      return AggregateCall.create(aggregation, agg.isDistinct(), false, false, argList, -1,
              RelCollations.of(collationList), aggFnRetType, null);
    }
This method creates a HiveFilter containing a filter expression to enforce constraints.
Constraints to check: not null, check
The return value is the pair of Constraint HiveFilter and the corresponding RowResolver
or null if the target has no constraint defined or all of them are disabled.
ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java