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
