Class CogroupedKStreamImpl<K,VOut>
- java.lang.Object
-
- org.apache.kafka.streams.kstream.internals.AbstractStream<K,VOut>
-
- org.apache.kafka.streams.kstream.internals.CogroupedKStreamImpl<K,VOut>
-
- All Implemented Interfaces:
CogroupedKStream<K,VOut>
public class CogroupedKStreamImpl<K,VOut> extends AbstractStream<K,VOut> implements CogroupedKStream<K,VOut>
-
-
Field Summary
-
Fields inherited from class org.apache.kafka.streams.kstream.internals.AbstractStream
builder, keySerde, name, streamsGraphNode, subTopologySourceNodes, valSerde
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description KTable<K,VOut>aggregate(Initializer<VOut> initializer)Aggregate the values of records in these streams by the grouped key.KTable<K,VOut>aggregate(Initializer<VOut> initializer, Materialized<K,VOut,KeyValueStore<org.apache.kafka.common.utils.Bytes,byte[]>> materialized)Aggregate the values of records in these streams by the grouped key.KTable<K,VOut>aggregate(Initializer<VOut> initializer, Named named)Aggregate the values of records in these streams by the grouped key.KTable<K,VOut>aggregate(Initializer<VOut> initializer, Named named, Materialized<K,VOut,KeyValueStore<org.apache.kafka.common.utils.Bytes,byte[]>> materialized)Aggregate the values of records in these streams by the grouped key.<VIn> CogroupedKStream<K,VOut>cogroup(KGroupedStream<K,VIn> groupedStream, Aggregator<? super K,? super VIn,VOut> aggregator)Add an alreadygrouped KStreamto thisCogroupedKStream.SessionWindowedCogroupedKStream<K,VOut>windowedBy(SessionWindows sessionWindows)Create a newSessionWindowedCogroupedKStreaminstance that can be used to perform session windowed aggregations.<W extends Window>
TimeWindowedCogroupedKStream<K,VOut>windowedBy(Windows<W> windows)Create a newTimeWindowedCogroupedKStreaminstance that can be used to perform windowed aggregations.-
Methods inherited from class org.apache.kafka.streams.kstream.internals.AbstractStream
internalTopologyBuilder, keySerde, valueSerde
-
-
-
-
Method Detail
-
cogroup
public <VIn> CogroupedKStream<K,VOut> cogroup(KGroupedStream<K,VIn> groupedStream, Aggregator<? super K,? super VIn,VOut> aggregator)
Description copied from interface:CogroupedKStreamAdd an alreadygrouped KStreamto thisCogroupedKStream.The added
grouped KStreammust have the same number of partitions as all existing streams of thisCogroupedKStream. If this is not the case, you would need to callKStream.repartition(Repartitioned)beforegroupingtheKStreamand specify the "correct" number of partitions viaRepartitionedparameter.The specified
Aggregatoris applied in the actualaggregationstep for each input record and computes a new aggregate using the current aggregate (or for the very first record per key using the initial intermediate aggregation result provided via theInitializerthat is passed intoCogroupedKStream.aggregate(Initializer)) and the record's value.- Specified by:
cogroupin interfaceCogroupedKStream<K,VOut>- Type Parameters:
VIn- Type of input values- Parameters:
groupedStream- a group streamaggregator- anAggregatorthat computes a new aggregate result- Returns:
- a
CogroupedKStream
-
aggregate
public KTable<K,VOut> aggregate(Initializer<VOut> initializer, Materialized<K,VOut,KeyValueStore<org.apache.kafka.common.utils.Bytes,byte[]>> materialized)
Description copied from interface:CogroupedKStreamAggregate the values of records in these streams by the grouped key. Records withnullkey or value are ignored. The result is written into a localKeyValueStore(which is basically an ever-updating materialized view) that can be queried by the given store name inmaterialized. Furthermore, updates to the store are sent downstream into aKTablechangelog stream.To compute the aggregation the corresponding
Aggregatoras specified incogroup(...)is used per input stream. The specifiedInitializeris applied once per key, directly before the first input record per key is processed to provide an initial intermediate aggregation result that is used to process the first record.Not all updates might get sent downstream, as an internal cache is used to deduplicate consecutive updates to the same key. The rate of propagated updates depends on your input data rate, the number of distinct keys, the number of parallel running Kafka Streams instances, and the
configurationparameters forcache size, andcommit intervall.To query the local
ReadOnlyKeyValueStoreit must be obtained viaKafkaStreams#store(...):KafkaStreams streams = ... // some aggregation on value type double String queryableStoreName = "storeName" // the store name should be the name of the store as defined by the Materialized instance ReadOnlyKeyValueStore
For non-local keys, a custom RPC mechanism must be implemented using> localStore = streams.store(queryableStoreName, QueryableStoreTypes. > timestampedKeyValueStore()); K key = "some-key"; ValueAndTimestamp aggForKey = localStore.get(key); // key must be local (application state is shared over all running Kafka Streams instances) } KafkaStreams.allMetadata()to query the value of the key on a parallel running instance of your Kafka Streams application.For failure and recovery the store will be backed by an internal changelog topic that will be created in Kafka. Therefore, the store name defined by the Materialized instance must be a valid Kafka topic name and cannot contain characters other than ASCII alphanumerics, '.', '_' and '-'. The changelog topic will be named "${applicationId}-${storeName}-changelog", where "applicationId" is user-specified in
StreamsConfigvia parameterAPPLICATION_ID_CONFIG, "storeName" is the provide store name defined inMaterialized, and "-changelog" is a fixed suffix.You can retrieve all generated internal topic names via
Topology.describe().- Specified by:
aggregatein interfaceCogroupedKStream<K,VOut>- Parameters:
initializer- anInitializerthat computes an initial intermediate aggregation result. Cannot benull.materialized- an instance ofMaterializedused to materialize a state store. Cannot benull.- Returns:
- a
KTablethat contains "update" records with unmodified keys, and values that represent the latest (rolling) aggregate for each key
-
aggregate
public KTable<K,VOut> aggregate(Initializer<VOut> initializer, Named named)
Description copied from interface:CogroupedKStreamAggregate the values of records in these streams by the grouped key. Records withnullkey or value are ignored. The result is written into a localKeyValueStore(which is basically an ever-updating materialized view) that can be queried by the given store name inmaterialized. Furthermore, updates to the store are sent downstream into aKTablechangelog stream.To compute the aggregation the corresponding
Aggregatoras specified incogroup(...)is used per input stream. The specifiedInitializeris applied once per key, directly before the first input record per key is processed to provide an initial intermediate aggregation result that is used to process the first record. The specifiedNamedis applied once to the processor combining the grouped streams.Not all updates might get sent downstream, as an internal cache is used to deduplicate consecutive updates to the same key. The rate of propagated updates depends on your input data rate, the number of distinct keys, the number of parallel running Kafka Streams instances, and the
configurationparameters forcache size, andcommit intervall.To query the local
ReadOnlyKeyValueStoreit must be obtained viaKafkaStreams#store(...):
For non-local keys, a custom RPC mechanism must be implemented usingKafkaStreams streams = ... // some aggregation on value type double String queryableStoreName = "storeName" // the store name should be the name of the store as defined by the Materialized instance ReadOnlyKeyValueStore<K, ValueAndTimestamp<VOut>> localStore = streams.store(queryableStoreName, QueryableStoreTypes.<K, ValueAndTimestamp<VOut>> timestampedKeyValueStore()); K key = "some-key"; ValueAndTimestamp<VOut> aggForKey = localStore.get(key); // key must be local (application state is shared over all running Kafka Streams instances)KafkaStreams.allMetadata()to query the value of the key on a parallel running instance of your Kafka Streams application.For failure and recovery the store will be backed by an internal changelog topic that will be created in Kafka. Therefore, the store name defined by the Materialized instance must be a valid Kafka topic name and cannot contain characters other than ASCII alphanumerics, '.', '_' and '-'. The changelog topic will be named "${applicationId}-${storeName}-changelog", where "applicationId" is user-specified in
StreamsConfigvia parameterAPPLICATION_ID_CONFIG, "storeName" is the provide store name defined inMaterialized, and "-changelog" is a fixed suffix.You can retrieve all generated internal topic names via
Topology.describe().- Specified by:
aggregatein interfaceCogroupedKStream<K,VOut>- Parameters:
initializer- anInitializerthat computes an initial intermediate aggregation result. Cannot benull.named- name the processor. Cannot benull.- Returns:
- a
KTablethat contains "update" records with unmodified keys, and values that represent the latest (rolling) aggregate for each key
-
aggregate
public KTable<K,VOut> aggregate(Initializer<VOut> initializer, Named named, Materialized<K,VOut,KeyValueStore<org.apache.kafka.common.utils.Bytes,byte[]>> materialized)
Description copied from interface:CogroupedKStreamAggregate the values of records in these streams by the grouped key. Records withnullkey or value are ignored. The result is written into a localKeyValueStore(which is basically an ever-updating materialized view) that can be queried by the given store name inmaterialized. Furthermore, updates to the store are sent downstream into aKTablechangelog stream.To compute the aggregation the corresponding
Aggregatoras specified incogroup(...)is used per input stream. The specifiedInitializeris applied once per key, directly before the first input record per key is processed to provide an initial intermediate aggregation result that is used to process the first record. The specifiedNamedis used to name the processor combining the grouped streams.Not all updates might get sent downstream, as an internal cache is used to deduplicate consecutive updates to the same key. The rate of propagated updates depends on your input data rate, the number of distinct keys, the number of parallel running Kafka Streams instances, and the
configurationparameters forcache size, andcommit intervall.To query the local
ReadOnlyKeyValueStoreit must be obtained viaKafkaStreams#store(...):KafkaStreams streams = ... // some aggregation on value type double String queryableStoreName = "storeName" // the store name should be the name of the store as defined by the Materialized instance ReadOnlyKeyValueStore
For non-local keys, a custom RPC mechanism must be implemented using> localStore = streams.store(queryableStoreName, QueryableStoreTypes. > timestampedKeyValueStore()); K key = "some-key"; ValueAndTimestamp aggForKey = localStore.get(key); // key must be local (application state is shared over all running Kafka Streams instances) } KafkaStreams.allMetadata()to query the value of the key on a parallel running instance of your Kafka Streams application.For failure and recovery the store will be backed by an internal changelog topic that will be created in Kafka. Therefore, the store name defined by the Materialized instance must be a valid Kafka topic name and cannot contain characters other than ASCII alphanumerics, '.', '_' and '-'. The changelog topic will be named "${applicationId}-${storeName}-changelog", where "applicationId" is user-specified in
StreamsConfigvia parameterAPPLICATION_ID_CONFIG, "storeName" is the provide store name defined inMaterialized, and "-changelog" is a fixed suffix.You can retrieve all generated internal topic names via
Topology.describe().- Specified by:
aggregatein interfaceCogroupedKStream<K,VOut>- Parameters:
initializer- anInitializerthat computes an initial intermediate aggregation result. Cannot benull.named- name the processors. Cannot benull.materialized- an instance ofMaterializedused to materialize a state store. Cannot benull.- Returns:
- a
KTablethat contains "update" records with unmodified keys, and values that represent the latest (rolling) aggregate for each key
-
aggregate
public KTable<K,VOut> aggregate(Initializer<VOut> initializer)
Description copied from interface:CogroupedKStreamAggregate the values of records in these streams by the grouped key. Records withnullkey or value are ignored. The result is written into a localKeyValueStore(which is basically an ever-updating materialized view) that can be queried by the given store name inmaterialized. Furthermore, updates to the store are sent downstream into aKTablechangelog stream.To compute the aggregation the corresponding
Aggregatoras specified incogroup(...)is used per input stream. The specifiedInitializeris applied once per key, directly before the first input record per key is processed to provide an initial intermediate aggregation result that is used to process the first record.Not all updates might get sent downstream, as an internal cache is used to deduplicate consecutive updates to the same key. The rate of propagated updates depends on your input data rate, the number of distinct keys, the number of parallel running Kafka Streams instances, and the
configurationparameters forcache size, andcommit intervall.To query the local
ReadOnlyKeyValueStoreit must be obtained viaKafkaStreams#store(...):
For non-local keys, a custom RPC mechanism must be implemented usingKafkaStreams streams = ... // some aggregation on value type double String queryableStoreName = "storeName" // the store name should be the name of the store as defined by the Materialized instance ReadOnlyKeyValueStore<K, ValueAndTimestamp<VOut>> localStore = streams.store(queryableStoreName, QueryableStoreTypes.<K, ValueAndTimestamp<VOut>> timestampedKeyValueStore()); K key = "some-key"; ValueAndTimestamp<VOut> aggForKey = localStore.get(key); // key must be local (application state is shared over all running Kafka Streams instances)KafkaStreams.allMetadata()to query the value of the key on a parallel running instance of your Kafka Streams application.For failure and recovery the store will be backed by an internal changelog topic that will be created in Kafka. Therefore, the store name defined by the Materialized instance must be a valid Kafka topic name and cannot contain characters other than ASCII alphanumerics, '.', '_' and '-'. The changelog topic will be named "${applicationId}-${storeName}-changelog", where "applicationId" is user-specified in
StreamsConfigvia parameterAPPLICATION_ID_CONFIG, "storeName" is a generated value, and "-changelog" is a fixed suffix.You can retrieve all generated internal topic names via
Topology.describe().- Specified by:
aggregatein interfaceCogroupedKStream<K,VOut>- Parameters:
initializer- anInitializerthat computes an initial intermediate aggregation result. Cannot benull.- Returns:
- a
KTablethat contains "update" records with unmodified keys, and values that represent the latest (rolling) aggregate for each key
-
windowedBy
public <W extends Window> TimeWindowedCogroupedKStream<K,VOut> windowedBy(Windows<W> windows)
Description copied from interface:CogroupedKStreamCreate a newTimeWindowedCogroupedKStreaminstance that can be used to perform windowed aggregations.- Specified by:
windowedByin interfaceCogroupedKStream<K,VOut>- Type Parameters:
W- the window type- Parameters:
windows- the specification of the aggregationWindows- Returns:
- an instance of
TimeWindowedCogroupedKStream
-
windowedBy
public SessionWindowedCogroupedKStream<K,VOut> windowedBy(SessionWindows sessionWindows)
Description copied from interface:CogroupedKStreamCreate a newSessionWindowedCogroupedKStreaminstance that can be used to perform session windowed aggregations.- Specified by:
windowedByin interfaceCogroupedKStream<K,VOut>- Parameters:
sessionWindows- the specification of the aggregationSessionWindows- Returns:
- an instance of
SessionWindowedCogroupedKStream
-
-