
com.hazelcast.jet.aggregate.CoAggregateOperationBuilder Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hazelcast.jet.aggregate;
import com.hazelcast.function.BiConsumerEx;
import com.hazelcast.function.FunctionEx;
import com.hazelcast.internal.util.Preconditions;
import com.hazelcast.jet.core.Processor;
import com.hazelcast.jet.datamodel.ItemsByTag;
import com.hazelcast.jet.datamodel.Tag;
import com.hazelcast.jet.pipeline.StageWithKeyAndWindow;
import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.stream.Stream;
import static com.hazelcast.function.FunctionEx.identity;
import static com.hazelcast.internal.serialization.impl.SerializationUtil.checkSerializable;
import static java.util.Arrays.stream;
import static java.util.stream.Collectors.toList;
import static java.util.stream.IntStream.range;
/**
* Offers a step-by-step API to create an aggregate operation that
* accepts multiple inputs. To obtain it, call {@link
* AggregateOperations#coAggregateOperationBuilder()}. and refer to that
* method's Javadoc for further details.
*
* @since Jet 3.0
*/
public class CoAggregateOperationBuilder {
private final Map opsByTag = new HashMap<>();
CoAggregateOperationBuilder() { }
/**
* Registers the given aggregate operation with the tag corresponding to an
* input to the co-aggregating operation being built. If you are preparing
* an operation to pass to an {@linkplain
* StageWithKeyAndWindow#aggregateBuilder() aggregate builder}, you must
* use the tags you obtained from it.
*
* Returns the tag you'll use to retrieve the results of aggregating this
* input.
*
* @param type of this operation's input
* @param the result type of this operation
* @return the result tag
*/
@Nonnull
@SuppressWarnings("unchecked")
public Tag add(
@Nonnull Tag tag,
@Nonnull AggregateOperation1 super T, ?, ? extends R> operation
) {
opsByTag.put(tag, operation);
return (Tag) tag;
}
/**
* Builds and returns the {@link AggregateOperation}. Its result type is
* {@link ItemsByTag} containing all the tags you got from the
* {@link #add} method.
*/
@Nonnull
public AggregateOperation
© 2015 - 2025 Weber Informatics LLC | Privacy Policy