A
- the type of the accumulatorR
- the type of the final resultpublic interface AggregateOperation<A,R> extends Serializable
accumulate
function for each of
them.
This is a summary of all the primitives involved:
create
a new accumulator object
accumulate
the data of an item by mutating
the accumulator
combine
the contents of the right-hand
accumulator into the left-hand one
deduct
the contents of the right-hand
accumulator from the left-hand one (undo the effects of combine
)
finish
accumulation by transforming the
accumulator object into the final result
There are specializations of this interface for up to three contributing
streams whose type they statically capture. They are AggregateOperation1
, AggregateOperation2
and AggregateOperation3
. If you use the provided builder object
, it will automatically
return the appropriate static type, depending on which accumulate
primitives you have provided.
Modifier and Type | Method and Description |
---|---|
<T> DistributedBiConsumer<? super A,? super T> |
accumulateFn(int index)
A primitive that updates the accumulator state to account for a new
item.
|
default <T> DistributedBiConsumer<? super A,? super T> |
accumulateFn(Tag<T> tag)
A primitive that updates the accumulator state to account for a new
item.
|
DistributedBiConsumer<? super A,? super A> |
combineFn()
A primitive that accepts two accumulators and updates the state of the
left-hand one by combining it with the state of the right-hand one.
|
DistributedSupplier<A> |
createFn()
A primitive that returns a new accumulator.
|
DistributedBiConsumer<? super A,? super A> |
deductFn()
A primitive that accepts two accumulators and updates the state of the
left-hand one by deducting the state of the right-hand one from it.
|
DistributedFunction<? super A,R> |
finishFn()
A primitive that finishes the accumulation process by transforming
the accumulator object into the final result.
|
default <T> AggregateOperation1<T,A,R> |
withCombiningAccumulateFn(DistributedFunction<T,A> getAccFn)
Returns a copy of this aggregate operation, but with the
accumulate primitive replaced with one that expects to find
accumulator objects in the input and will combine them all into
a single accumulator of the same type. |
static <A> AggregateOperationBuilder<A> |
withCreate(DistributedSupplier<A> createFn)
Returns a builder object, initialized with the supplied
create
primitive, that can be used to construct the definition of an aggregate
operation in a step-by-step manner. |
<R_NEW> AggregateOperation<A,R_NEW> |
withFinishFn(DistributedFunction<? super A,R_NEW> finishFn)
Returns a copy of this aggregate operation, but with the
finish
primitive replaced with the supplied one. |
@Nonnull DistributedSupplier<A> createFn()
deduct
primitive is defined, the accumulator object must properly implement
equals()
, which will be used to detect when an accumulator is
"empty" (i.e., equal to a fresh instance returned from this method) and
can be evicted from a processor's storage.@Nonnull default <T> DistributedBiConsumer<? super A,? super T> accumulateFn(@Nonnull Tag<T> tag)
@Nonnull <T> DistributedBiConsumer<? super A,? super T> accumulateFn(int index)
@Nullable DistributedBiConsumer<? super A,? super A> combineFn()
null
.@Nullable DistributedBiConsumer<? super A,? super A> deductFn()
The effect of this primitive must be the opposite of combine
so that
combine(acc, x); deduct(acc, x);leaves
acc
in the same state as it was before the two
operations.
Note: this primitive is only used in sliding window aggregation and even in that case it is optional, but its presence may significantly reduce the computational cost. With it, the current sliding window can be obtained from the previous one by deducting the trailing frame and combining the leading frame; without it, each window must be recomputed from all its constituent frames. The finer the sliding step, the more pronounced the difference in computation effort will be.
@Nonnull DistributedFunction<? super A,R> finishFn()
@Nonnull <R_NEW> AggregateOperation<A,R_NEW> withFinishFn(@Nonnull DistributedFunction<? super A,R_NEW> finishFn)
finish
primitive replaced with the supplied one.R_NEW
- the new aggregation result typefinishFn
- the new finish
primitive@Nonnull default <T> AggregateOperation1<T,A,R> withCombiningAccumulateFn(@Nonnull DistributedFunction<T,A> getAccFn)
accumulate
primitive replaced with one that expects to find
accumulator objects in the input and will combine them all into
a single accumulator of the same type.T
- the type of stream itemgetAccFn
- the function that extracts the accumulator from the stream item@Nonnull static <A> AggregateOperationBuilder<A> withCreate(@Nonnull DistributedSupplier<A> createFn)
create
primitive, that can be used to construct the definition of an aggregate
operation in a step-by-step manner.
The same builder is used to construct both fixed- and variable-arity aggregate operations:
andAccumulate0()
, optionally followed by .andAccumulate1()
,
.andAccumulate2()
. The return type of these methods changes as the
static types of the contributing streams are captured.
andAccumulate(tag)
.
andFinish()
method returns the constructed aggregate operation. Its
static type receives all the type parameters captured in the above
method calls. If your aggregate operation doesn't need a finishing
transformation (the accumulator itself is the result value), you
can call the shorthand andIdentityFinish()
.A
- the type of the accumulatorcreateFn
- the create
primitivecreate
primitive definedCopyright © 2017 Hazelcast, Inc.. All Rights Reserved.