LAST_KAFKA_MESSAGE_ID()¶
LAST_KAFKA_MESSAGE_ID()returns the Kafka offset of the last message a completed Kafka external-table scan returned in this session, orNULLbefore any scan. Feeding it back as the next__mo_read_start_idchains reads exactly once.
Description¶
LAST_KAFKA_MESSAGE_ID() is a session builtin that reads back the progress of the most recent completed Kafka external-table scan. The value is plain session state and does not survive a proxy connection migration, where the builtin then returns NULL until the next scan.
Syntax¶
SELECT LAST_KAFKA_MESSAGE_ID();
Arguments¶
LAST_KAFKA_MESSAGE_ID() takes no arguments. It reads the session state recorded by the most recent completed Kafka external-table scan.
Usage Notes¶
Returns
NULLbefore any completed Kafka scan in the session.With
autocommit=false, using the value as the next__mo_read_start_idreads the messages after the last returned offset, giving exactly-once consumption.Progress publishes only when the whole statement succeeds; an aborted or failed statement never advances the value.
Examples¶
The following example shows the NULL-before-scan value without a Kafka broker:
DROP DATABASE IF EXISTS kafka_id_demo;
CREATE DATABASE kafka_id_demo;
USE kafka_id_demo;
SELECT last_kafka_message_id();
DROP DATABASE kafka_id_demo;
Chaining reads requires a reachable broker, so it is shown as a syntax template rather than a paste-and-run script:
SELECT * FROM kt WHERE __mo_read_start_id = 1000 AND __mo_read_size = 100000;
SELECT last_kafka_message_id(); -- e.g. 4711
SELECT * FROM kt WHERE __mo_read_start_id = 4711; -- continues after