A stream–global table join enriches each KStream record with matching metadata from a fully replicated GlobalKTable. Unlike ordinary stream–table joins, it does not require co-partitioning, so the stream may use null keys or keys unrelated to the global table. section 8.6 section 8.6.3
Use the join when:
- The stream records lack keys, but a field in each value identifies the matching global-table record. section 8.6.3
- The stream key differs from the GlobalKTable key and must be translated before lookup. section 8.6.3
- The application needs an enriched event containing information from both the incoming stream record and replicated reference data. section 8.6
The KStream–GlobalKTable API takes three main components: the stream, the GlobalKTable, and a KeyValueMapper. The mapper receives the stream key and value and returns the key used to query the global table. A ValueJoiner then combines the stream value with the matched table value. The resulting record retains the stream’s key, even when that key is null or differs from the lookup key. section 8.6.3
Enriching unkeyed sensor readings
A manufacturing application reads sensor measurements without Kafka keys and joins them with a GlobalKTable containing sensor metadata. The mapper extracts the sensor ID from the Sensor value, while the joiner combines the reading with location information: sensorKStream.join(sensorInfoGlobalKTable, sensorIdExtractor, sensorValueJoiner). Kafka Streams updates the GlobalKTable through a separate dedicated thread outside normal incoming-record processing. section 8.6.3
Listing 8.10 KstreamGlobalTable join example
sensorKStream.join(sensorInfoGlobalKTable, #1
sensorIdExtractor, #2
sensorValueJoiner); #3
Inspect the compact three-argument KStream–GlobalKTable join shape before following the mapper and value-joiner details. section 8.6.3
