The documentation re KGroupedTable#aggregate
at https://kafka.apache.org/26/documentation/streams/developer-guide/dsl-api.html#streams-developer-guide-dsl-aggregating states:
When subsequent non-null values are received for a key (e.g., UPDATE), then (1) the subtractor is called with the old value as stored in the table and (2) the adder is called with the new value of the input record that was just received. The order of execution for the subtractor and adder is not defined.
The phrase “the order of execution for the subtractor and adder is not defined” seems to warn against making any assumptions re their order of execution.
Viewing the source I find that the order of execution does seem to be defined:
And (cross-post alert) I filed a question here about the Kafka Music Example:
which also seems to rely on the current behavior (subtractor is called first, then adder). Or am I missing something? Would that Kafka Music Example work correctly even if adder were called first, then subtractor? (I don’t see how it would; but perhaps I’m missing something)
I’m curious to hear from fellow users of KGroupedTable#aggregate. Do you rely on an explicit order (subtractor first, etc.)?