Code review comment: the rule only takes effect only when group by keys contain all unique key. If group by key is (colA, colB) but unique key is (colA, colB, colC), we cannot remove the agg.

Code under review:
public boolean check(OptExpression input, OptimizerContext context) {
        LogicalAggregationOperator aggOp = input.getOp().cast();
        if (aggOp.getGroupingKeys().isEmpty()) {
            return false;
        }

        for (Map.Entry<ColumnRefOperator, CallOperator> entry : aggOp.getAggregations().entrySet()) {
            String fnName = entry.getValue().getFnName();
            if (!(fnName.equals(FunctionSet.SUM) || fnName.equals(FunctionSet.COUNT) ||
                    fnName.equals(FunctionSet.AVG) ||
                    fnName.equals(FunctionSet.FIRST_VALUE) ||
                    fnName.equals(FunctionSet.MAX) || fnName.equals(FunctionSet.MIN) ||
                    fnName.equals(FunctionSet.GROUP_CONCAT))) {
                return false;
            }
        }

        
        UKFKConstraintsCollector collector = new UKFKConstraintsCollector();
        input.getOp().accept(collector, input, null);

        OptExpression childOptExpression = input.inputAt(0);
        for (ColumnRefOperator columnRefOperator : aggOp.getGroupingKeys()) {
            if (childOptExpression.getConstraints().getUniqueConstraint(columnRefOperator.getId()) == null) {
                return false;
            }
        }

        return true;
    }

Line commented on: if (childOptExpression.getConstraints().getUniqueConstraint(columnRefOperator.getId()) == null) {

Revised code:
public boolean check(OptExpression input, OptimizerContext context) {
        LogicalAggregationOperator aggOp = input.getOp().cast();
        List<ColumnRefOperator> groupKeys = aggOp.getGroupingKeys();

        for (Map.Entry<ColumnRefOperator, CallOperator> entry : aggOp.getAggregations().entrySet()) {
            if (entry.getValue().isDistinct()) {
                return false;
            }
            String fnName = entry.getValue().getFnName();
            if (!(fnName.equals(FunctionSet.SUM) || fnName.equals(FunctionSet.COUNT) ||
                    fnName.equals(FunctionSet.AVG) ||
                    fnName.equals(FunctionSet.FIRST_VALUE) ||
                    fnName.equals(FunctionSet.MAX) || fnName.equals(FunctionSet.MIN) ||
                    fnName.equals(FunctionSet.GROUP_CONCAT))) {
                return false;
            }
        }

        
        UKFKConstraintsCollector collector = new UKFKConstraintsCollector();
        input.getOp().accept(collector, input, null);

        OptExpression childOptExpression = input.inputAt(0);
        Map<Integer, UKFKConstraints.UniqueConstraintWrapper> uniqueKeys =
                childOptExpression.getConstraints().getTableUniqueKeys();
        if (uniqueKeys.isEmpty()) {
            return false;
        }
        if (uniqueKeys.size() != groupKeys.size()) {
            return false;
        }

        Set<Integer> groupColumnRefIds = groupKeys.stream()
                .map(ColumnRefOperator::getId)
                .collect(Collectors.toSet());

        Set<Integer> uniqueColumnRefIds =
                uniqueKeys.keySet().stream().collect(Collectors.toSet());
        if (!groupColumnRefIds.equals(uniqueColumnRefIds)) {
            return false;
        }

        return true;
    }