class IgniteAggregate extends Aggregate implements IgniteRel {
    /** */
    protected IgniteAggregate(
        RelOptCluster cluster,
        RelTraitSet traitSet,
        RelNode input,
        ImmutableBitSet groupSet,
        List<ImmutableBitSet> groupSets,
        List<AggregateCall> aggCalls
    ) {
        super(cluster, traitSet, ImmutableList.of(), input, groupSet, groupSets, aggCalls);
    }

    /** */
    protected IgniteAggregate(RelInput input) {
        super(changeTraits(input, IgniteConvention.INSTANCE));
    }

    /** {@inheritDoc} */
    @Override public double estimateRowCount(RelMetadataQuery mq) {
        Double grpsCnt = mq.getDistinctRowCount(getInput(), groupSet, null);

        if (grpsCnt != null)
            return grpsCnt;

        // Estimation of the groups count is not available.
        // Use heuristic estimation for result rows count.
        return super.estimateRowCount(mq);
    }

    /** */
    public double estimateMemoryForGroup(RelMetadataQuery mq) {<FILL_FUNCTION_BODY>}

    /** */
    public RelOptCost computeSelfCostHash(RelOptPlanner planner, RelMetadataQuery mq) {
        IgniteCostFactory costFactory = (IgniteCostFactory)planner.getCostFactory();

        double inRows = mq.getRowCount(getInput());
        double grps = estimateRowCount(mq);

        return costFactory.makeCost(
            inRows,
            inRows * IgniteCost.ROW_PASS_THROUGH_COST,
            0,
            grps * estimateMemoryForGroup(mq),
            0
        );
    }

    /** */
    public RelOptCost computeSelfCostSort(RelOptPlanner planner, RelMetadataQuery mq) {
        IgniteCostFactory costFactory = (IgniteCostFactory)planner.getCostFactory();

        double inRows = mq.getRowCount(getInput());

        return costFactory.makeCost(
            inRows,
            inRows * IgniteCost.ROW_PASS_THROUGH_COST,
            0,
            estimateMemoryForGroup(mq),
            0
        );
    }
}

        double mem = groupSet.cardinality() * IgniteCost.AVERAGE_FIELD_SIZE;

        if (!aggCalls.isEmpty()) {
            double grps = estimateRowCount(mq);
            double rows = input.estimateRowCount(mq);

            for (AggregateCall aggCall : aggCalls) {
                if (aggCall.isDistinct())
                    mem += IgniteCost.AGG_CALL_MEM_COST * rows / grps;
                else
                    mem += IgniteCost.AGG_CALL_MEM_COST;
            }
        }

        return mem;
    
<no_super_class>