Reputation: 273
I am running following query on ksql. but I want only last 20 records.
SELECT MAX(ROWTIME),TIMESTAMPTOSTRING(ROWTIME, 'yyyy-MM-dd HH:mm:ss'),SERIAL,COUNT FROM MY_STREAM WHERE TIMESTAMPTOSTRING(ROWTIME, 'yyyy-MM-dd HH:mm:ss') >= DATE AND TIMESTAMPTOSTRING(ROWTIME, 'yyyy-MM-dd HH:mm:ss') <= DATE2 GROUP BY SERIAL,COUNT LIMIT 20;
Upvotes: 3
Views: 3415
Reputation: 32090
You can't do that in KSQL currently. Since KSQL is dealing with unbounded data, the 'last' records don't make so much sense, because the data is (potentially) always arriving.
Depending on what you're trying to do you could use ROWTIME
predicate to filter data based on a time range.
Possibly you will need to use Kafka Streams instead to access the data in the pattern you're describing.
You might want to also check for existing issue to upvote here: https://github.com/confluentinc/ksql/issues/ and if there isn't one, create one https://github.com/confluentinc/ksql/issues/new
Upvotes: 3