lowka commented on code in PR #4522: URL: https://github.com/apache/ignite-3/pull/4522#discussion_r1796457075
########## modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/exp/agg/Accumulators.java: ########## @@ -541,27 +619,35 @@ public RelDataType returnType(IgniteTypeFactory typeFactory) { } } - private static class DecimalSumEmptyIsZero implements Accumulator { + /** SUM(DECIMAL) accumulator. */ + public static class DecimalSumEmptyIsZero implements Accumulator { public static final Supplier<Accumulator> FACTORY = DecimalSumEmptyIsZero::new; - private BigDecimal sum = BigDecimal.ZERO; - /** {@inheritDoc} */ @Override - public void add(Object... args) { + public void add(AccumulatorsState state, Object... args) { BigDecimal in = (BigDecimal) args[0]; if (in == null) { return; } - sum = sum.add(in); + BigDecimal sum = (BigDecimal) state.get(); + if (sum == null) { + state.set(in); + } else { + state.set(sum.add(in)); + } } /** {@inheritDoc} */ @Override - public Object end() { - return sum; + public void end(AccumulatorsState state, AccumulatorsState result) { + if (!state.hasValue()) { Review Comment: This requires 3 replacing Sum(XXSumEmptyIsZero) with SumXXX aggregates. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org