Click to copy

• Reviewed for ksqlDB 0.29

How to Get a Topic Sample in ksqlDB

If you want to gain a general idea about a topic, you can read a limited number of messages. To display a sample of messages, you can use the PRINT command alongside the LIMIT modifier.

PRINT 'topicName' FROM BEGINNING LIMIT 10;

This SQL statement will print the first 10 records in the topic.

Reading non-consecutive messages

Since the same scope or client usually produces messages in chunks, you might only have a partial understanding of the topic if you get 10 consecutive records.

Let’s say you want a statistically significant sample from the topic. You can use the INTERVAL modifier to jump messages and only print one every X consumed messages.

PRINT 'topicName' FROM BEGINNING INTERVAL 100 LIMIT 10;

This statement will print the 1st, 101st, 201st… messages until you received 10.

Discover what readers are saying
topictale
Get easy to digest how-tos on ksqlDB
Sign up
Please read our Privacy Policy to understand how we protect and manage your data.
You may also like