public final class AggregateOperations extends Object
AggregateOperation
. You can
also create your own aggregate operation using the builder object
.Modifier and Type | Method and Description |
---|---|
static <T0,T1,A0,A1,R0,R1> |
aggregateOperation2(AggregateOperation1<? super T0,A0,? extends R0> op0,
AggregateOperation1<? super T1,A1,? extends R1> op1)
Convenience for
aggregateOperation2(aggrOp0, aggrOp1, finishFn) that outputs a
Tuple2(result0, result1) . |
static <T0,A0,R0,T1,A1,R1,R> |
aggregateOperation2(AggregateOperation1<? super T0,A0,? extends R0> op0,
AggregateOperation1<? super T1,A1,? extends R1> op1,
BiFunctionEx<? super R0,? super R1,? extends R> exportFinishFn)
Returns an aggregate operation that is a composite of two independent
aggregate operations, each one accepting its own input.
|
static <T0,T1,T2,A0,A1,A2,R0,R1,R2> |
aggregateOperation3(AggregateOperation1<? super T0,A0,? extends R0> op0,
AggregateOperation1<? super T1,A1,? extends R1> op1,
AggregateOperation1<? super T2,A2,? extends R2> op2)
Convenience for
aggregateOperation3(aggrOp0, aggrOp1, aggrOp2, finishFn) that outputs a
Tuple3(result0, result1, result2) . |
static <T0,T1,T2,A0,A1,A2,R0,R1,R2,R> |
aggregateOperation3(AggregateOperation1<? super T0,A0,? extends R0> op0,
AggregateOperation1<? super T1,A1,? extends R1> op1,
AggregateOperation1<? super T2,A2,? extends R2> op2,
TriFunction<? super R0,? super R1,? super R2,? extends R> exportFinishFn)
Returns an aggregate operation that is a composite of three independent
aggregate operations, each one accepting its own input.
|
static <T,A0,A1,A2,R0,R1,R2> |
allOf(AggregateOperation1<? super T,A0,? extends R0> op0,
AggregateOperation1<? super T,A1,? extends R1> op1,
AggregateOperation1<? super T,A2,? extends R2> op2)
Convenience for
allOf(AggregateOperation1, AggregateOperation1,
AggregateOperation1, TriFunction) with identity finisher. |
static <T,A0,A1,A2,R0,R1,R2,R> |
allOf(AggregateOperation1<? super T,A0,? extends R0> op0,
AggregateOperation1<? super T,A1,? extends R1> op1,
AggregateOperation1<? super T,A2,? extends R2> op2,
TriFunction<? super R0,? super R1,? super R2,? extends R> exportFinishFn)
Returns an aggregate operation that is a composite of three aggregate
operations.
|
static <T,A0,A1,R0,R1,R> |
allOf(AggregateOperation1<? super T,A0,? extends R0> op0,
AggregateOperation1<? super T,A1,? extends R1> op1,
BiFunctionEx<? super R0,? super R1,? extends R> exportFinishFn)
Returns an aggregate operation that is a composite of two aggregate
operations.
|
static <T,A0,A1,R0,R1> |
allOf(AggregateOperation1<? super T,A0,R0> op1,
AggregateOperation1<? super T,A1,R1> op2)
Convenience for
allOf(AggregateOperation1, AggregateOperation1,
BiFunctionEx) with identity finish. |
static <T> AllOfAggregationBuilder<T> |
allOfBuilder()
Returns a builder object that helps you create a composite of multiple
aggregate operations.
|
static <T> AggregateOperation1<T,LongDoubleAccumulator,Double> |
averagingDouble(ToDoubleFunctionEx<? super T> getDoubleValueFn)
Returns an aggregate operation that computes the arithmetic mean of the
double values it obtains by applying getDoubleValueFn to
each item. |
static <T> AggregateOperation1<T,LongLongAccumulator,Double> |
averagingLong(ToLongFunctionEx<? super T> getLongValueFn)
Returns an aggregate operation that computes the arithmetic mean of the
long values it obtains by applying getLongValueFn to
each item. |
static <T> AggregateOperation1<T,PriorityQueue<T>,List<T>> |
bottomN(int n,
ComparatorEx<? super T> comparator)
Returns an aggregate operation that computes the bottom
n items
calculated according to the given comparator . |
static CoAggregateOperationBuilder |
coAggregateOperationBuilder()
Returns a builder object that offers a step-by-step fluent API to create
an aggregate operation that accepts multiple inputs.
|
static AggregateOperation1<CharSequence,StringBuilder,String> |
concatenating()
Returns an aggregate operation that concatenates the input items into a
string.
|
static AggregateOperation1<CharSequence,StringBuilder,String> |
concatenating(CharSequence delimiter)
Returns an aggregate operation that concatenates the input items into a
string with the given
delimiter . |
static AggregateOperation1<CharSequence,StringBuilder,String> |
concatenating(CharSequence delimiter,
CharSequence prefix,
CharSequence suffix)
Returns an aggregate operation that concatenates the input items into a
string with the given
delimiter . |
static <T> AggregateOperation1<T,LongAccumulator,Long> |
counting()
Returns an aggregate operation that computes the number of items.
|
static <T,K> AggregateOperation1<T,Map<K,List<T>>,Map<K,List<T>>> |
groupingBy(FunctionEx<? super T,? extends K> keyFn)
Returns an
AggregateOperation1 that accumulates the items into a
HashMap where the key is the result of applying keyFn
and the value is a list of the items with that key. |
static <T,K,A,R> AggregateOperation1<T,Map<K,A>,Map<K,R>> |
groupingBy(FunctionEx<? super T,? extends K> keyFn,
AggregateOperation1<? super T,A,R> downstream)
Returns an
AggregateOperation1 that accumulates the items into a
HashMap where the key is the result of applying keyFn
and the value is the result of applying the downstream aggregate
operation to the items with that key. |
static <T,K,R,A,M extends Map<K,R>> |
groupingBy(FunctionEx<? super T,? extends K> keyFn,
SupplierEx<M> createMapFn,
AggregateOperation1<? super T,A,R> downstream)
Returns an
AggregateOperation1 that accumulates the items into a
Map (as obtained from createMapFn ) where the key is the
result of applying keyFn and the value is the result of
applying the downstream aggregate operation to the items with that key. |
static <T> AggregateOperation1<T,LinTrendAccumulator,Double> |
linearTrend(ToLongFunctionEx<T> getXFn,
ToLongFunctionEx<T> getYFn)
Returns an aggregate operation that computes a linear trend on the items.
|
static <T,U,A,R> AggregateOperation1<T,A,R> |
mapping(FunctionEx<? super T,? extends U> mapFn,
AggregateOperation1<? super U,A,? extends R> downstream)
Adapts an aggregate operation accepting items of type
U to one accepting items of type T by applying a mapping
function to each item before accumulation. |
static <T> AggregateOperation1<T,MutableReference<T>,T> |
maxBy(ComparatorEx<? super T> comparator)
Returns an aggregate operation that computes the maximal item according
to the given
comparator . |
static <T> AggregateOperation1<T,MutableReference<T>,T> |
minBy(ComparatorEx<? super T> comparator)
Returns an aggregate operation that computes the minimal item according
to the given
comparator . |
static <T> AggregateOperation1<T,MutableReference<T>,T> |
pickAny()
Returns an aggregate operation whose result is an arbitrary item it
observed, or
null if it observed no items. |
static <T,A> AggregateOperation1<T,MutableReference<A>,A> |
reducing(A emptyAccValue,
FunctionEx<? super T,? extends A> toAccValueFn,
BinaryOperatorEx<A> combineAccValuesFn,
BinaryOperatorEx<A> deductAccValueFn)
A reducing operation maintains an accumulated value that starts out as
emptyAccValue and is iteratively transformed by applying
combineAccValuesFn to it and each stream item's accumulated
value, as returned from toAccValueFn . |
static <T> AggregateOperation1<T,ArrayList<T>,List<T>> |
sorting(ComparatorEx<? super T> comparator)
Returns an aggregate operation that accumulates all input items into an
ArrayList and sorts it with the given comparator. |
static <T> AggregateOperation1<T,DoubleAccumulator,Double> |
summingDouble(ToDoubleFunctionEx<? super T> getDoubleValueFn)
Returns an aggregate operation that computes the sum of the
double
values it obtains by applying getDoubleValueFn to each item. |
static <T> AggregateOperation1<T,LongAccumulator,Long> |
summingLong(ToLongFunctionEx<? super T> getLongValueFn)
Returns an aggregate operation that computes the sum of the
long
values it obtains by applying getLongValueFn to each item. |
static <T,C extends Collection<T>> |
toCollection(SupplierEx<C> createCollectionFn)
Returns an aggregate operation that accumulates the items into a
Collection . |
static <T> AggregateOperation1<T,List<T>,List<T>> |
toList()
Returns an aggregate operation that accumulates the items into an
ArrayList . |
static <T,K,U> AggregateOperation1<T,Map<K,U>,Map<K,U>> |
toMap(FunctionEx<? super T,? extends K> keyFn,
FunctionEx<? super T,? extends U> valueFn)
Returns an aggregate operation that accumulates the items into a
HashMap whose keys and values are the result of applying
the provided mapping functions. |
static <T,K,U> AggregateOperation1<T,Map<K,U>,Map<K,U>> |
toMap(FunctionEx<? super T,? extends K> keyFn,
FunctionEx<? super T,? extends U> valueFn,
BinaryOperatorEx<U> mergeFn)
Returns an aggregate operation that accumulates the items into a
HashMap whose keys and values are the result of applying
the provided mapping functions. |
static <T,K,U,M extends Map<K,U>> |
toMap(FunctionEx<? super T,? extends K> keyFn,
FunctionEx<? super T,? extends U> valueFn,
BinaryOperatorEx<U> mergeFn,
SupplierEx<M> createMapFn)
Returns an
AggregateOperation1 that accumulates elements
into a Map whose keys and values are the result of applying the
provided mapping functions to the input elements. |
static <T> AggregateOperation1<T,PriorityQueue<T>,List<T>> |
topN(int n,
ComparatorEx<? super T> comparator)
Returns an aggregate operation that computes the top
n items
calculated according to the given comparator . |
static <T> AggregateOperation1<T,Set<T>,Set<T>> |
toSet()
Returns an aggregate operation that accumulates the items into a
HashSet . |
@Nonnull public static <T> AggregateOperation1<T,LongAccumulator,Long> counting()
@Nonnull public static <T> AggregateOperation1<T,LongAccumulator,Long> summingLong(@Nonnull ToLongFunctionEx<? super T> getLongValueFn)
long
values it obtains by applying getLongValueFn
to each item.T
- input item type@Nonnull public static <T> AggregateOperation1<T,DoubleAccumulator,Double> summingDouble(@Nonnull ToDoubleFunctionEx<? super T> getDoubleValueFn)
double
values it obtains by applying getDoubleValueFn
to each item.T
- input item type@Nonnull public static <T> AggregateOperation1<T,MutableReference<T>,T> minBy(@Nonnull ComparatorEx<? super T> comparator)
comparator
.
This aggregate operation does not implement the deduct
primitive.
T
- input item type@Nonnull public static <T> AggregateOperation1<T,MutableReference<T>,T> maxBy(@Nonnull ComparatorEx<? super T> comparator)
comparator
.
This aggregate operation does not implement the deduct
primitive.
T
- input item type@Nonnull public static <T> AggregateOperation1<T,PriorityQueue<T>,List<T>> topN(int n, @Nonnull ComparatorEx<? super T> comparator)
n
items
calculated according to the given comparator
.
The returned list of elements is sorted in descending order.
This aggregate operation does not implement the deduct
primitive.
T
- input item typen
- number of items to returncomparator
- the comparator to use@Nonnull public static <T> AggregateOperation1<T,PriorityQueue<T>,List<T>> bottomN(int n, @Nonnull ComparatorEx<? super T> comparator)
n
items
calculated according to the given comparator
.
The returned list of elements is sorted in ascending order.
This aggregate operation does not implement the deduct
primitive.
T
- input item typen
- number of items to returncomparator
- the comparator to use@Nonnull public static <T> AggregateOperation1<T,LongLongAccumulator,Double> averagingLong(@Nonnull ToLongFunctionEx<? super T> getLongValueFn)
long
values it obtains by applying getLongValueFn
to
each item.T
- input item type@Nonnull public static <T> AggregateOperation1<T,LongDoubleAccumulator,Double> averagingDouble(@Nonnull ToDoubleFunctionEx<? super T> getDoubleValueFn)
double
values it obtains by applying getDoubleValueFn
to
each item.T
- input item type@Nonnull public static <T> AggregateOperation1<T,LinTrendAccumulator,Double> linearTrend(@Nonnull ToLongFunctionEx<T> getXFn, @Nonnull ToLongFunctionEx<T> getYFn)
double
-valued coefficient that
approximates the rate of change of y
as a function of x
,
where x
and y
are long
quantities obtained
by applying the two provided functions to each item.public static AggregateOperation1<CharSequence,StringBuilder,String> concatenating()
public static AggregateOperation1<CharSequence,StringBuilder,String> concatenating(CharSequence delimiter)
delimiter
.public static AggregateOperation1<CharSequence,StringBuilder,String> concatenating(CharSequence delimiter, CharSequence prefix, CharSequence suffix)
delimiter
. The resulting string will also
have the given prefix
and suffix
.public static <T,U,A,R> AggregateOperation1<T,A,R> mapping(@Nonnull FunctionEx<? super T,? extends U> mapFn, @Nonnull AggregateOperation1<? super U,A,? extends R> downstream)
U
to one accepting items of type T
by applying a mapping
function to each item before accumulation.
If the mapFn
returns null
, the item won't be aggregated
at all. This allows applying a filter at the same time.
T
- input item typeU
- input type of the downstream aggregate operationA
- downstream operation's accumulator typeR
- downstream operation's result typemapFn
- the function to apply to input itemsdownstream
- the downstream aggregate operationpublic static <T,C extends Collection<T>> AggregateOperation1<T,C,C> toCollection(SupplierEx<C> createCollectionFn)
Collection
. It creates the collections as needed by calling the
provided createCollectionFn
.
If you use a collection that preserves the insertion order, keep in mind that there is no specified order in which the items are aggregated.
T
- input item typeC
- the type of the collectioncreateCollectionFn
- a Supplier
which returns a new, empty Collection
of the
appropriate typepublic static <T> AggregateOperation1<T,List<T>,List<T>> toList()
ArrayList
.T
- input item typepublic static <T> AggregateOperation1<T,Set<T>,Set<T>> toSet()
HashSet
.T
- input item typepublic static <T,K,U> AggregateOperation1<T,Map<K,U>,Map<K,U>> toMap(FunctionEx<? super T,? extends K> keyFn, FunctionEx<? super T,? extends U> valueFn)
HashMap
whose keys and values are the result of applying
the provided mapping functions.
This aggregate operation does not tolerate duplicate keys and will
throw IllegalStateException
if it detects them. If your
data contains duplicates, use the toMap()
overload
that can resolve them.
T
- input item typeK
- type of the keyU
- type of the valuekeyFn
- a function to extract the key from the input itemvalueFn
- a function to extract the value from the input itemtoMap(FunctionEx, FunctionEx, BinaryOperatorEx)
,
toMap(FunctionEx, FunctionEx, BinaryOperatorEx, SupplierEx)
public static <T,K,U> AggregateOperation1<T,Map<K,U>,Map<K,U>> toMap(FunctionEx<? super T,? extends K> keyFn, FunctionEx<? super T,? extends U> valueFn, BinaryOperatorEx<U> mergeFn)
HashMap
whose keys and values are the result of applying
the provided mapping functions.
This aggregate operation resolves duplicate keys by applying mergeFn
to the conflicting values. mergeFn
will act upon the
values after valueFn
has already been applied.
T
- input item typeK
- the type of keyU
- the output type of the value mapping functionkeyFn
- a function to extract the key from input itemvalueFn
- a function to extract value from input itemmergeFn
- a merge function, used to resolve collisions between
values associated with the same key, as supplied
to Map.merge(Object, Object,
java.util.function.BiFunction)
toMap(FunctionEx, FunctionEx)
,
toMap(FunctionEx, FunctionEx, BinaryOperatorEx, SupplierEx)
public static <T,K,U,M extends Map<K,U>> AggregateOperation1<T,M,M> toMap(FunctionEx<? super T,? extends K> keyFn, FunctionEx<? super T,? extends U> valueFn, BinaryOperatorEx<U> mergeFn, SupplierEx<M> createMapFn)
AggregateOperation1
that accumulates elements
into a Map
whose keys and values are the result of applying the
provided mapping functions to the input elements.
If the mapped keys contain duplicates (according to Object.equals(Object)
), the value mapping function is applied to each
equal element, and the results are merged using the provided merging
function. The Map
is created by a provided createMapFn
function.
T
- input item typeK
- the output type of the key mapping functionU
- the output type of the value mapping functionM
- the type of the resulting Map
keyFn
- a function to extract the key from input itemvalueFn
- a function to extract value from input itemmergeFn
- a merge function, used to resolve collisions between
values associated with the same key, as supplied
to Map.merge(Object, Object,
java.util.function.BiFunction)
createMapFn
- a function which returns a new, empty Map
into
which the results will be insertedtoMap(FunctionEx, FunctionEx)
,
toMap(FunctionEx, FunctionEx, BinaryOperatorEx)
public static <T,K> AggregateOperation1<T,Map<K,List<T>>,Map<K,List<T>>> groupingBy(FunctionEx<? super T,? extends K> keyFn)
AggregateOperation1
that accumulates the items into a
HashMap
where the key is the result of applying keyFn
and the value is a list of the items with that key.
This operation achieves the effect of a cascaded group-by where the members of each group are further classified by a secondary key.
T
- input item typeK
- the output type of the key mapping functionkeyFn
- a function to extract the key from input itemgroupingBy(FunctionEx, AggregateOperation1)
,
groupingBy(FunctionEx, SupplierEx, AggregateOperation1)
public static <T,K,A,R> AggregateOperation1<T,Map<K,A>,Map<K,R>> groupingBy(FunctionEx<? super T,? extends K> keyFn, AggregateOperation1<? super T,A,R> downstream)
AggregateOperation1
that accumulates the items into a
HashMap
where the key is the result of applying keyFn
and the value is the result of applying the downstream aggregate
operation to the items with that key.
This operation achieves the effect of a cascaded group-by where the members of each group are further classified by a secondary key.
T
- input item typeK
- the output type of the key mapping functionR
- the type of the downstream aggregation resultA
- downstream aggregation's accumulator typekeyFn
- a function to extract the key from input itemdownstream
- the downstream aggregate operationgroupingBy(FunctionEx)
,
groupingBy(FunctionEx, SupplierEx, AggregateOperation1)
public static <T,K,R,A,M extends Map<K,R>> AggregateOperation1<T,Map<K,A>,M> groupingBy(FunctionEx<? super T,? extends K> keyFn, SupplierEx<M> createMapFn, AggregateOperation1<? super T,A,R> downstream)
AggregateOperation1
that accumulates the items into a
Map
(as obtained from createMapFn
) where the key is the
result of applying keyFn
and the value is the result of
applying the downstream aggregate operation to the items with that key.
This operation achieves the effect of a cascaded group-by where the members of each group are further classified by a secondary key.
T
- input item typeK
- the output type of the key mapping functionR
- the type of the downstream aggregation resultA
- downstream aggregation's accumulator typeM
- output type of the resulting Map
keyFn
- a function to extract the key from input itemcreateMapFn
- a function which returns a new, empty Map
into
which the results will be inserteddownstream
- the downstream aggregate operationgroupingBy(FunctionEx)
,
groupingBy(FunctionEx, AggregateOperation1)
@Nonnull public static <T,A> AggregateOperation1<T,MutableReference<A>,A> reducing(@Nonnull A emptyAccValue, @Nonnull FunctionEx<? super T,? extends A> toAccValueFn, @Nonnull BinaryOperatorEx<A> combineAccValuesFn, @Nullable BinaryOperatorEx<A> deductAccValueFn)
emptyAccValue
and is iteratively transformed by applying
combineAccValuesFn
to it and each stream item's accumulated
value, as returned from toAccValueFn
. combineAccValuesFn
must be associative because it will also be used to combine
partial results, as well as commutative because the encounter
order of items is unspecified.
The optional deductAccValueFn
allows Jet to compute the sliding
window in O(1) time. It must undo the effects of a previous combineAccValuesFn
call:
A accVal; (has some pre-existing value) A itemAccVal = toAccValueFn.apply(item); A combined = combineAccValuesFn.apply(accVal, itemAccVal); A deducted = deductAccValueFn.apply(combined, itemAccVal); assert deducted.equals(accVal);
T
- input item typeA
- type of the accumulated valueemptyAccValue
- the reducing operation's emptyAccValue elementtoAccValueFn
- transforms the stream item into its accumulated valuecombineAccValuesFn
- combines two accumulated values into onedeductAccValueFn
- deducts the right-hand accumulated value from the left-hand one
(optional)@Nonnull public static <T> AggregateOperation1<T,MutableReference<T>,T> pickAny()
null
if it observed no items.
The implementation of StageWithWindow.distinct()
uses this
operation and, if needed, you can use it directly for the same purpose.
For example, in a stream of Person objects you can specify the last name
as the key. The result will be a stream of Person objects, one for each
distinct last name:
Pipeline p = Pipeline.create(); p.<Person>drawFrom(list("persons")) .groupingKey(Person::getLastName) .aggregate(pickAny()) .drainTo(...);
public static <T> AggregateOperation1<T,ArrayList<T>,List<T>> sorting(@Nonnull ComparatorEx<? super T> comparator)
ArrayList
and sorts it with the given comparator. Use ComparatorEx.naturalOrder()
if you want to sort Comparable
items by their natural order.T
- the type of input itemscomparator
- the comparator to use for sorting@Nonnull public static <T,A0,A1,R0,R1,R> AggregateOperation1<T,Tuple2<A0,A1>,R> allOf(@Nonnull AggregateOperation1<? super T,A0,? extends R0> op0, @Nonnull AggregateOperation1<? super T,A1,? extends R1> op1, @Nonnull BiFunctionEx<? super R0,? super R1,? extends R> exportFinishFn)
T
- type of input itemsA0
- 1st accumulator typeA1
- 2nd accumulator typeR0
- 1st result typeR1
- 2nd result typeR
- final result typeop0
- 1st operationop1
- 2nd operationexportFinishFn
- function combining the two results into a single target instance@Nonnull public static <T,A0,A1,R0,R1> AggregateOperation1<T,Tuple2<A0,A1>,Tuple2<R0,R1>> allOf(@Nonnull AggregateOperation1<? super T,A0,R0> op1, @Nonnull AggregateOperation1<? super T,A1,R1> op2)
allOf(AggregateOperation1, AggregateOperation1,
BiFunctionEx)
with identity finish.@Nonnull public static <T,A0,A1,A2,R0,R1,R2,R> AggregateOperation1<T,Tuple3<A0,A1,A2>,R> allOf(@Nonnull AggregateOperation1<? super T,A0,? extends R0> op0, @Nonnull AggregateOperation1<? super T,A1,? extends R1> op1, @Nonnull AggregateOperation1<? super T,A2,? extends R2> op2, @Nonnull TriFunction<? super R0,? super R1,? super R2,? extends R> exportFinishFn)
T
- type of input itemsA0
- 1st accumulator typeA1
- 2nd accumulator typeA2
- 3rd accumulator typeR0
- 1st result typeR1
- 2nd result typeR2
- 3rd result typeR
- final result typeop0
- 1st operationop1
- 2nd operationop2
- 3rd operationexportFinishFn
- function combining the three results into a single target instance@Nonnull public static <T,A0,A1,A2,R0,R1,R2> AggregateOperation1<T,Tuple3<A0,A1,A2>,Tuple3<R0,R1,R2>> allOf(@Nonnull AggregateOperation1<? super T,A0,? extends R0> op0, @Nonnull AggregateOperation1<? super T,A1,? extends R1> op1, @Nonnull AggregateOperation1<? super T,A2,? extends R2> op2)
allOf(AggregateOperation1, AggregateOperation1,
AggregateOperation1, TriFunction)
with identity finisher.@Nonnull public static <T> AllOfAggregationBuilder<T> allOfBuilder()
ItemsByTag
object
you'll get in the output.
The builder object is primarily intended to build a composite of four or more
aggregate operations. For up to three operations, prefer the explicit, more
type-safe variants allOf(op1, op2)
and allOf(op1, op2, op3)
.
Example that calculates the count and the sum of the items:
AllOfAggregationBuilder<Long> builder = allOfBuilder();
Tag<Long> tagSum = builder.add(summingLong(Long::longValue));
Tag<Long> tagCount = builder.add(counting());
AggregateOperation1<Long, ?, ItemsByTag> compositeAggrOp = builder.build();
When you receive the resulting ItemsByTag
, fetch the individual results using the tags as keys, for example:
batchStage.aggregate(compositeAggrOp).map((ItemsByTag result) -> {
Long sum = result.get(tagSum);
Long count = result.get(tagCount);
...
});
T
- type of input itemspublic static <T0,A0,R0,T1,A1,R1,R> AggregateOperation2<T0,T1,Tuple2<A0,A1>,R> aggregateOperation2(@Nonnull AggregateOperation1<? super T0,A0,? extends R0> op0, @Nonnull AggregateOperation1<? super T1,A1,? extends R1> op1, @Nonnull BiFunctionEx<? super R0,? super R1,? extends R> exportFinishFn)
stage.aggregate2()
.
This method is suitable when you can express your computation as two independent aggregate operations where you combine only their final results. If you need an operation that combines the two inputs in the accumulation phase, you can create an aggregate operation by specifying each primitive using the aggregate operation builder.
T0
- type of items in the first stageA0
- type of the first aggregate operation's accumulatorR0
- type of the first aggregate operation's resultT1
- type of items in the second stageA1
- type of the second aggregate operation's accumulatorR1
- type of the second aggregate operation's resultR
- type of the resultop0
- the aggregate operation that will receive the first stage's inputop1
- the aggregate operation that will receive the second stage's inputexportFinishFn
- the function that transforms the individual aggregate results into the
overall result that the co-aggregating stage emitspublic static <T0,T1,A0,A1,R0,R1> AggregateOperation2<T0,T1,Tuple2<A0,A1>,Tuple2<R0,R1>> aggregateOperation2(@Nonnull AggregateOperation1<? super T0,A0,? extends R0> op0, @Nonnull AggregateOperation1<? super T1,A1,? extends R1> op1)
aggregateOperation2(aggrOp0, aggrOp1, finishFn)
that outputs a
Tuple2(result0, result1)
.T0
- type of items in the first stageA0
- type of the first aggregate operation's accumulatorR0
- type of the first aggregate operation's resultT1
- type of items in the second stageA1
- type of the second aggregate operation's accumulatorR1
- type of the second aggregate operation's resultop0
- the aggregate operation that will receive the first stage's inputop1
- the aggregate operation that will receive the second stage's inputpublic static <T0,T1,T2,A0,A1,A2,R0,R1,R2,R> AggregateOperation3<T0,T1,T2,Tuple3<A0,A1,A2>,R> aggregateOperation3(@Nonnull AggregateOperation1<? super T0,A0,? extends R0> op0, @Nonnull AggregateOperation1<? super T1,A1,? extends R1> op1, @Nonnull AggregateOperation1<? super T2,A2,? extends R2> op2, @Nonnull TriFunction<? super R0,? super R1,? super R2,? extends R> exportFinishFn)
stage.aggregate3()
.
This method is suitable when you can express your computation as three independent aggregate operations where you combine only their final results. If you need an operation that combines the three inputs in the accumulation phase, you can create an aggregate operation by specifying each primitive using the aggregate operation builder.
T0
- type of items in the first stageA0
- type of the first aggregate operation's accumulatorR0
- type of the first aggregate operation's resultT1
- type of items in the second stageA1
- type of the second aggregate operation's accumulatorR1
- type of the second aggregate operation's resultT2
- type of items in the third stageA2
- type of the third aggregate operation's accumulatorR2
- type of the third aggregate operation's resultR
- type of the resultop0
- the aggregate operation that will receive the first stage's inputop1
- the aggregate operation that will receive the second stage's inputop2
- the aggregate operation that will receive the third stage's inputexportFinishFn
- the function that transforms the individual aggregate results into the
overall result that the co-aggregating stage emitspublic static <T0,T1,T2,A0,A1,A2,R0,R1,R2> AggregateOperation3<T0,T1,T2,Tuple3<A0,A1,A2>,Tuple3<R0,R1,R2>> aggregateOperation3(@Nonnull AggregateOperation1<? super T0,A0,? extends R0> op0, @Nonnull AggregateOperation1<? super T1,A1,? extends R1> op1, @Nonnull AggregateOperation1<? super T2,A2,? extends R2> op2)
aggregateOperation3(aggrOp0, aggrOp1, aggrOp2, finishFn)
that outputs a
Tuple3(result0, result1, result2)
.T0
- type of items in the first stageA0
- type of the first aggregate operation's accumulatorR0
- type of the first aggregate operation's resultT1
- type of items in the second stageA1
- type of the second aggregate operation's accumulatorR1
- type of the second aggregate operation's resultT2
- type of items in the third stageA2
- type of the third aggregate operation's accumulatorR2
- type of the third aggregate operation's resultop0
- the aggregate operation that will receive the first stage's inputop1
- the aggregate operation that will receive the second stage's inputop2
- the aggregate operation that will receive the third stage's input@Nonnull public static CoAggregateOperationBuilder coAggregateOperationBuilder()
StageWithWindow.aggregateBuilder()
. For
two-way or three-way co-aggregation you can use aggregateOperation2(com.hazelcast.jet.aggregate.AggregateOperation1<? super T0, A0, ? extends R0>, com.hazelcast.jet.aggregate.AggregateOperation1<? super T1, A1, ? extends R1>, com.hazelcast.jet.function.BiFunctionEx<? super R0, ? super R1, ? extends R>)
and aggregateOperation3(com.hazelcast.jet.aggregate.AggregateOperation1<? super T0, A0, ? extends R0>, com.hazelcast.jet.aggregate.AggregateOperation1<? super T1, A1, ? extends R1>, com.hazelcast.jet.aggregate.AggregateOperation1<? super T2, A2, ? extends R2>, com.hazelcast.jet.function.TriFunction<? super R0, ? super R1, ? super R2, ? extends R>)
.
This builder is suitable when you can express your computation as independent aggregate operations on each input where you combine only their final results. If you need an operation that combines the inputs in the accumulation phase, you can create an aggregate operation by specifying each primitive using the aggregate operation builder.
Copyright © 2019 Hazelcast, Inc.. All rights reserved.