There are two ways of querying data in ksqlDB: push queries and pull queries.
EMIT CHANGESclause. By running a push query, the client will receive a message for every change that occurs on the stream (that is, every new message).
SELECTstatement executed on a regular RDBMS. They can only be used against ksqlDB tables with materialized state, that is, a table in which there is an aggregate function. Currently, tables declared against an existing Apache Kafka topic cannot be queried with a pull query (as of ksqlDB v0.15 / February 2021).
Applying this to the aggregate
ORDERS_PER_HOUR_BY_MAKE table from Stateful Aggregations (Materialized Views), we can query it both ways. A pull query returns the current state of the aggregate:
New events will update the aggregate, but we’d need to execute the pull query again in order to see the new value:
Compare this to a push query against the same table. Here, we receive a continuous stream of all changes to the aggregate:
We will only share developer content and updates, including notifications when new content is added. We will never send you sales emails. 🙂 By subscribing, you understand we will process your personal information in accordance with our Privacy Statement.