Click to copy
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.
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.