Interface IMapExtension.IMapBatchStageWithKey<T,K>
- Type Parameters:
T- type of the stream itemK- type of the grouping key
- All Superinterfaces:
IMapExtension.IMapGeneralStageWithKey<T,K>
- Enclosing interface:
- IMapExtension<T,
K>
BatchStageWithKey.mapUsingIMap(java.lang.String, com.hazelcast.function.BiFunctionEx<? super T, ? super V, ? extends R>) available in basic stages.- Since:
- 5.7
-
Method Summary
Modifier and TypeMethodDescriptiondefault <V,R> com.hazelcast.jet.pipeline.BatchStage<R> mapUsingPutIfAbsent(com.hazelcast.map.IMap<K, V> iMap, com.hazelcast.function.FunctionEx<? super T, ? extends V> newValueFn, com.hazelcast.jet.function.TriFunction<? super T, ? super V, ? super V, ? extends R> mapFn) Attaches a mapping stage where for each item aIMap.putIfAbsent(K, V)operation is performed in the suppliedIMap.<V,R> com.hazelcast.jet.pipeline.BatchStage<R> mapUsingPutIfAbsent(String mapName, com.hazelcast.function.FunctionEx<? super T, ? extends V> newValueFn, com.hazelcast.jet.function.TriFunction<? super T, ? super V, ? super V, ? extends R> mapFn) Attaches a mapping stage where for each item aIMap.putIfAbsent(K, V)operation is performed in the suppliedIMap.
-
Method Details
-
mapUsingPutIfAbsent
@Nonnull <V,R> com.hazelcast.jet.pipeline.BatchStage<R> mapUsingPutIfAbsent(@Nonnull String mapName, @Nonnull com.hazelcast.function.FunctionEx<? super T, ? extends V> newValueFn, @Nonnull com.hazelcast.jet.function.TriFunction<? super T, ? super V, ? super V, ? extends R> mapFn) Attaches a mapping stage where for each item aIMap.putIfAbsent(K, V)operation is performed in the suppliedIMap. The result ofIMap.putIfAbsent(K, V)(previous value associated with the key or null) is merged with the item and emitted.If the result of the mapping is
null, it emits nothing. Therefore, this stage can be used to implement filtering semantics as well.The mapping logic is equivalent to:
V newValue = newValueFn.apply(item); V prevValue = map.putIfAbsent(key, newValue); return mapFn.apply(item, prevValue, newValue);This operation and the IMap do not participate in Jet's fault tolerance protocol. If upstream stage or source retries processing, it will be invoked again. However, keep in mind that
IMap.putIfAbsent(K, V)is not idempotent: when retried it may produce a different result (previous value) than in the original invocation. The mapping function and pipeline logic must be able to deal with this.This method does not use transactions for IMap. All updates to IMap are immediately visible regardless of Jet's fault tolerance protocol (snapshots).
- Specified by:
mapUsingPutIfAbsentin interfaceIMapExtension.IMapGeneralStageWithKey<T,K> - Type Parameters:
V- type of the value in theIMapR- type of the output item- Parameters:
mapName- name of theIMapnewValueFn- a function which returns the IMap value to be associated with the key. Must not return null. It must be stateless and cooperative.mapFn- the mapping function. It must be stateless and cooperative.- Returns:
- the newly attached stage
-
mapUsingPutIfAbsent
@Nonnull default <V,R> com.hazelcast.jet.pipeline.BatchStage<R> mapUsingPutIfAbsent(@Nonnull com.hazelcast.map.IMap<K, V> iMap, @Nonnull com.hazelcast.function.FunctionEx<? super T, ? extends V> newValueFn, @Nonnull com.hazelcast.jet.function.TriFunction<? super T, ? super V, ? super V, ? extends R> mapFn) Attaches a mapping stage where for each item aIMap.putIfAbsent(K, V)operation is performed in the suppliedIMap. The result ofIMap.putIfAbsent(K, V)(previous value associated with the key or null) is merged with the item and emitted.If the result of the mapping is
null, it emits nothing. Therefore, this stage can be used to implement filtering semantics as well.The mapping logic is equivalent to:
V newValue = newValueFn.apply(item); V prevValue = map.putIfAbsent(key, newValue); return mapFn.apply(item, prevValue, newValue);This operation and the IMap do not participate in Jet's fault tolerance protocol. If upstream stage or source retries processing, it will be invoked again. However, keep in mind that
IMap.putIfAbsent(K, V)is not idempotent: when retried it may produce a different result (previous value) than in the original invocation. The mapping function and pipeline logic must be able to deal with this.This method does not use transactions for IMap. All updates to IMap are immediately visible regardless of Jet's fault tolerance protocol (snapshots).
- Specified by:
mapUsingPutIfAbsentin interfaceIMapExtension.IMapGeneralStageWithKey<T,K> - Type Parameters:
V- type of the value in theIMapR- type of the output item- Parameters:
iMap- theIMapto usenewValueFn- a function which returns the IMap value to be associated with the key. Must not return null. It must be stateless and cooperative.mapFn- the mapping function. It must be stateless and cooperative.- Returns:
- the newly attached stage
-