Maksim Zhuravkov created IGNITE-23335:
-----------------------------------------

             Summary: Sql. Do not store aggregation state in Accumulator
                 Key: IGNITE-23335
                 URL: https://issues.apache.org/jira/browse/IGNITE-23335
             Project: Ignite
          Issue Type: Improvement
          Components: sql
            Reporter: Maksim Zhuravkov


`Accumulator` stores aggregation state, we should extract this state making  
`Accumulator` pure functions.

Current accumulator (except methods that return result types). 
{code:java}
public interface Accumulator {
    void add(Object... args);

    Object end();
{code}

DoubleAvg example:

{code:java}
public static class DoubleAvg implements Accumulator {
        public static final Supplier<Accumulator> FACTORY = DoubleAvg::new;

        private double sum;

        private long cnt;

        /** {@inheritDoc} */
        @Override
        public void add(Object... args) {
            Double in = (Double) args[0];

            if (in == null) {
                return;
            }

            sum += in;
            cnt++;
        }

        /** {@inheritDoc} */
        @Override
        public Object end() {
            return cnt > 0 ? sum / cnt : null;
        }
{code}

{code:java}
public interface Accumulator {
    void init(AggregateState state);

    void update(AggregateState state, arguments);

    void end(AggregateState state);
{code}

Aggregate should be stored in aggregate operators (HashAggregateNode, ). We 
should also move DistinctAccumulator  (AVG(DISTINCT x) to HashAggregateNode





--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to