private boolean isAggWithConstantGbyKeys(final Aggregate aggregate, RelOptRuleCall call) {
    final RexBuilder rexBuilder = aggregate.getCluster().getRexBuilder();
    final RelMetadataQuery mq = call.getMetadataQuery();
    final RelOptPredicateList predicates =
        mq.getPulledUpPredicates(aggregate.getInput());
    if (predicates == null) {
      return false;
    }
    final NavigableMap<Integer, RexNode> map = new TreeMap<>();
    for (int key : aggregate.getGroupSet()) {
      final RexInputRef ref =
          rexBuilder.makeInputRef(aggregate.getInput(), key);
      if (predicates.constantMap.containsKey(ref)) {
        map.put(key, predicates.constantMap.get(ref));
      }
    }

    // None of the group expressions are constant. Nothing to do.
    if (map.isEmpty()) {
      return false;
    }

    final int groupCount = aggregate.getGroupCount();
    if (groupCount == map.size()) {
      return true;
    }
    return false;
  }
Planner rule that removes UDF sq_count_check from a plan if
 1) either group by keys in a subquery are constant and there is no windowing or grouping sets
 2) OR there are no group by keys but only aggregate
 Both of the above case will produce at most one row, therefore it is safe to remove sq_count_check
   which was introduced earlier in the plan to ensure that this condition is met at run time
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveRemoveSqCountCheck.java