### Question:
DecimalSumAggregation extends SqlAggregationFunction { public static void combine(LongDecimalWithOverflowState state, LongDecimalWithOverflowState otherState) { state.setOverflow(state.getOverflow() + otherState.getOverflow()); if (state.getLongDecimal() == null) { state.setLongDecimal(otherState.getLongDecimal()); } else { accumulateValueInState(otherState.getLongDecimal(), state); } } DecimalSumAggregation(); @Override List<TypeSignature> getIntermediateTypes(FunctionBinding functionBinding); @Override InternalAggregationFunction specialize(FunctionBinding functionBinding); static void inputShortDecimal(Type type, LongDecimalWithOverflowState state, Block block, int position); static void inputLongDecimal(Type type, LongDecimalWithOverflowState state, Block block, int position); static void combine(LongDecimalWithOverflowState state, LongDecimalWithOverflowState otherState); static void outputLongDecimal(DecimalType type, LongDecimalWithOverflowState state, BlockBuilder out); static final DecimalSumAggregation DECIMAL_SUM_AGGREGATION; }### Answer:
@Test public void testCombineOverflow() { addToState(state, TWO.pow(125)); addToState(state, TWO.pow(126)); LongDecimalWithOverflowState otherState = new LongDecimalWithOverflowStateFactory().createSingleState(); addToState(otherState, TWO.pow(125)); addToState(otherState, TWO.pow(126)); DecimalSumAggregation.combine(state, otherState); assertEquals(state.getOverflow(), 1); assertEquals(state.getLongDecimal(), unscaledDecimal(TWO.pow(126))); }
@Test public void testCombineUnderflow() { addToState(state, TWO.pow(125).negate()); addToState(state, TWO.pow(126).negate()); LongDecimalWithOverflowState otherState = new LongDecimalWithOverflowStateFactory().createSingleState(); addToState(otherState, TWO.pow(125).negate()); addToState(otherState, TWO.pow(126).negate()); DecimalSumAggregation.combine(state, otherState); assertEquals(state.getOverflow(), -1); assertEquals(state.getLongDecimal(), unscaledDecimal(TWO.pow(126).negate())); }