KGroupedStream — Basic Stream Aggregations

KGroupedStream is the abstraction of a grouped record stream that allows Kafka Streams developers for aggregate, count, reduce and windowedBy stream aggregations.

KGroupedStream is the result of the following aggregate stream operators:

Tip
Use Scala API for Kafka Streams to make your Kafka Streams development more pleasant if Scala is your programming language.
import org.apache.kafka.streams.scala.StreamsBuilder
import org.apache.kafka.streams.scala._
import ImplicitConversions._
import Serdes._
val builder = new StreamsBuilder
val groupedKStream = builder
  .stream[String, String]("events")
  .groupByKey
scala> :type groupedKStream
org.apache.kafka.streams.scala.kstream.KGroupedStream[String,String]
Table 1. KGroupedStream API / Aggregation Operators
Method Description

aggregate

KTable<K, VR> aggregate(
  final Initializer<VR> initializer,
  final Aggregator<? super K, ? super V, VR> aggregator)
KTable<K, VR> aggregate(
  final Initializer<VR> initializer,
  final Aggregator<? super K, ? super V, VR> aggregator,
  final Materialized<K, VR, KeyValueStore<Bytes, byte[]>> materialized)

Creates a KTable with a given Initializer, Aggregator and Materialized (view of a KeyValueStore)

count

KTable<K, Long> count()
KTable<K, Long> count(
  final Materialized<K, Long, KeyValueStore<Bytes, byte[]>> materialized)

Creates a KTable with a given Materialized (view of a KeyValueStore)

reduce

KTable<K, V> reduce(final Reducer<V> reducer)
KTable<K, V> reduce(
  final Reducer<V> reducer,
  final Materialized<K, V, KeyValueStore<Bytes, byte[]>> materialized)

Creates a KTable with a given Reducer and Materialized (view of a KeyValueStore)

windowedBy

SessionWindowedKStream<K, V> windowedBy(final SessionWindows windows)

Creates a SessionWindowedKStream with a given SessionWindows window specification

windowedBy

<W extends Window> TimeWindowedKStream<K, V> windowedBy(final Windows<W> windows)

Creates a TimeWindowedKStream with a given Windows window specification

Note
KGroupedStreamImpl is the one and only known implementation of the KGroupedStream Contract in Kafka Streams 2.3.0.

results matching ""

    No results matching ""