Search in sources :

Example 1 with BagsByTag

use of com.hazelcast.jet.datamodel.BagsByTag in project hazelcast-jet by hazelcast.

the class AggregateOperations method toBagsByTag.

/**
 * Returns an {@code AggregateOperation} that accumulates the items from
 * any number of inputs into {@link BagsByTag}: items from <em>inputN</em>
 * are accumulated into under <em>tagN</em>.
 *
 * @see #toTwoBags()
 * @see #toThreeBags()
 */
@Nonnull
@SuppressWarnings("unchecked")
public static AggregateOperation<BagsByTag, BagsByTag> toBagsByTag(@Nonnull Tag<?>... tags) {
    checkPositive(tags.length, "At least one tag required");
    AggregateOperationBuilder.VarArity<BagsByTag> builder = AggregateOperation.withCreate(BagsByTag::new).andAccumulate(tags[0], (acc, item) -> ((Collection) acc.ensureBag(tags[0])).add(item));
    for (int i = 1; i < tags.length; i++) {
        Tag tag = tags[i];
        builder = builder.andAccumulate(tag, (acc, item) -> acc.ensureBag(tag).add(item));
    }
    return builder.andCombine(BagsByTag::combineWith).andFinish(BagsByTag::finish);
}
Also used : MutableReference(com.hazelcast.jet.accumulator.MutableReference) DistributedBiConsumer(com.hazelcast.jet.function.DistributedBiConsumer) DistributedToLongFunction(com.hazelcast.jet.function.DistributedToLongFunction) DistributedBinaryOperator(com.hazelcast.jet.function.DistributedBinaryOperator) DistributedComparator(com.hazelcast.jet.function.DistributedComparator) HashMap(java.util.HashMap) DistributedTriFunction(com.hazelcast.jet.function.DistributedTriFunction) DistributedBiFunction(com.hazelcast.jet.function.DistributedBiFunction) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ThreeBags(com.hazelcast.jet.datamodel.ThreeBags) LinTrendAccumulator(com.hazelcast.jet.accumulator.LinTrendAccumulator) Map(java.util.Map) DistributedToDoubleFunction(com.hazelcast.jet.function.DistributedToDoubleFunction) Preconditions.checkPositive(com.hazelcast.util.Preconditions.checkPositive) DistributedFunction(com.hazelcast.jet.function.DistributedFunction) Nonnull(javax.annotation.Nonnull) Tuple2(com.hazelcast.jet.datamodel.Tuple2) Nullable(javax.annotation.Nullable) Tuple3(com.hazelcast.jet.datamodel.Tuple3) DistributedSupplier(com.hazelcast.jet.function.DistributedSupplier) Collection(java.util.Collection) Tag(com.hazelcast.jet.datamodel.Tag) Set(java.util.Set) LongDoubleAccumulator(com.hazelcast.jet.accumulator.LongDoubleAccumulator) Tuple3.tuple3(com.hazelcast.jet.datamodel.Tuple3.tuple3) List(java.util.List) BagsByTag(com.hazelcast.jet.datamodel.BagsByTag) Tuple2.tuple2(com.hazelcast.jet.datamodel.Tuple2.tuple2) LongLongAccumulator(com.hazelcast.jet.accumulator.LongLongAccumulator) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) DoubleAccumulator(com.hazelcast.jet.accumulator.DoubleAccumulator) TwoBags(com.hazelcast.jet.datamodel.TwoBags) BagsByTag(com.hazelcast.jet.datamodel.BagsByTag) Tag(com.hazelcast.jet.datamodel.Tag) BagsByTag(com.hazelcast.jet.datamodel.BagsByTag) Nonnull(javax.annotation.Nonnull)

Aggregations

DoubleAccumulator (com.hazelcast.jet.accumulator.DoubleAccumulator)1 LinTrendAccumulator (com.hazelcast.jet.accumulator.LinTrendAccumulator)1 LongAccumulator (com.hazelcast.jet.accumulator.LongAccumulator)1 LongDoubleAccumulator (com.hazelcast.jet.accumulator.LongDoubleAccumulator)1 LongLongAccumulator (com.hazelcast.jet.accumulator.LongLongAccumulator)1 MutableReference (com.hazelcast.jet.accumulator.MutableReference)1 BagsByTag (com.hazelcast.jet.datamodel.BagsByTag)1 Tag (com.hazelcast.jet.datamodel.Tag)1 ThreeBags (com.hazelcast.jet.datamodel.ThreeBags)1 Tuple2 (com.hazelcast.jet.datamodel.Tuple2)1 Tuple2.tuple2 (com.hazelcast.jet.datamodel.Tuple2.tuple2)1 Tuple3 (com.hazelcast.jet.datamodel.Tuple3)1 Tuple3.tuple3 (com.hazelcast.jet.datamodel.Tuple3.tuple3)1 TwoBags (com.hazelcast.jet.datamodel.TwoBags)1 DistributedBiConsumer (com.hazelcast.jet.function.DistributedBiConsumer)1 DistributedBiFunction (com.hazelcast.jet.function.DistributedBiFunction)1 DistributedBinaryOperator (com.hazelcast.jet.function.DistributedBinaryOperator)1 DistributedComparator (com.hazelcast.jet.function.DistributedComparator)1 DistributedFunction (com.hazelcast.jet.function.DistributedFunction)1 DistributedSupplier (com.hazelcast.jet.function.DistributedSupplier)1