liveBook · Manning

ksqlDB table

As explained in Kafka Streams in Action, Second Edition

A ksqlDB table is a persistent queryable representation of the latest value for each record key produced by a stateful query.

A ksqlDB table models an unbounded update stream: records sharing a key update the prior value for that key rather than remaining independent events. It provides a table-shaped view of changing keyed state, suitable for point-in-time queries against a materialized view. section 11.1 section 11.7

Create a table with a persistent query when an incoming stream must be aggregated into current results. The query continuously evaluates new Kafka-topic events and persists its results to a topic, allowing multiple clients to share them. GROUP BY determines the table key; composite keys require a key format that supports a schema, such as JSON. section 11.2 section 11.7

Maintain activity leaders

Aggregate fitness updates into one current total per person and activity. This table groups by first name, last name, and activity, then sums steps. JSON key format supports the multi-column grouping key. section 11.2

Listing 11.12 Adding a sum aggregation for calculating leaders in a category
CREATE TABLE activity_leaders AS     #1
  SELECT
     last_name,
     SUM(steps)           #2
FROM user_activity
GROUP BY last_name    #3
EMIT CHANGES;

This minimal table query shows the essential pattern: group stream records, aggregate them, and emit continually updated results. section 11.2

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Explains update semantics, continuous aggregation, grouping, composite-key formatting, and topic deletion without detailing table internals.
Examples
Builds an activity_leaders table using SUM(steps), GROUP BY, JSON composite keys, and AS_VALUE key copies.
What it assumes
Distinguishes independent event streams from keyed update streams before creating tables.
What you can do after
Builds persistent ksqlDB tables that continuously aggregate keyed Kafka-topic events.
How it connects
Connects TABLEs to KStream, KTable, STREAMs, persistent queries, pull queries, aggregations, and stream–table joins.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kafka Streams in Action, Second Edition. The section links point to the parts of the book it draws on.