r/sqlite • u/krolshkramber • 9h ago
Query Kafka topics with SQL from your SQL editor or terminal: KafCacheQL 0.5.0
Query Kafka data with SQL. No ksqlDB, no Flink, just a JDBC driver, a Kafka cluster and your SQL editor or a terminal.
Data pulled is cached locally in SQLite, so rerunning a query only fetches the new records.
This is a tool for platform engineers, data scientists/analysts, BI, or anyone who prefers to use SQL to interact with Kafka data without the need to write a Kafka client. All they need are credentials for a Kafka cluster (and Schema Registry, for schema-backed topics). It's also an easy way to onboard people who don't know Kafka and don't want to (or can't) spin up a sink connector.
Full disclosure, I work for Confluent, but this is a tool created for the Kafka community.
It is experimental, not recommended for production and not supposed to replace stream processing engines.
See below the full list of functionalities shipped on v0.5.0:
- One JDBC JAR: works in DBeaver, DataGrip, any Java app (Java 21+) or its own kafcacheql command line
- Kafka 3.1+: Confluent Cloud, Confluent Platform, self-managed or local
- Auth: PLAINTEXT, SSL/TLS (incl. client certificates), SASL_PLAINTEXT and SASL_SSL with PLAIN or SCRAM-SHA-256/512
- Confluent Cloud: API key over SASL_SSL, and the client.properties file Cloud generates works as-is
- Schema Registry with basic auth (API key and secret)
- Not supported (yet): OAuth/OAUTHBEARER and AWS MSK IAM
- Read-only (pull query style): it never writes to Kafka
- Topics show up as tables, and you get SQLite's SQL: joins, aggregations, JSON functions
- Compacted topics read as current state (tombstones handled), append topics as event history
- Every row has its partition, offset, timestamp, key, value and headers
- Avro, JSON Schema and Protobuf through Confluent Schema Registry, plus plain JSON, string and bytes. Schema fields become typed columns
- Schema evolution handled: columns come from every schema version in the topic, so fields added or removed over time all show up (NULL where a record doesn't have them), and if versions disagree on a field's type you get the raw value and a warning instead of a wrong conversion
- Local cache: reruns only fetch new records, and cached topics can be queried offline
- How fetching works:
- SELECT: fetches only what the query needs that isn't cached yet. That's limited by its window if you set one, and by default it's everything Kafka still holds
- SYNC: fetches everything new since the last cached offset, with no limit
- Both: stop at the end offsets they saw when they started, and anything produced after that comes with the next query
- No consumer group: each consumer is assigned one partition at a time and seeks straight to the offsets it needs, by default up to 8 consumers fetching in parallel (sync.fetch.parallelism). Offsets are kept in the SQLite cache, so nothing is committed to Kafka and there's no rebalancing
- Time/offset windows on big topics, plus fast "last N records" queries
- Cache size and age limits; cached data follows Kafka's retention
- Records that fail to decode still show up as rows, with the error and the raw bytes, handy for debugging
- Drop or mask fields (PII) before anything is written to the cache, or plug in your own Java transform
- The kafcacheql command line: interactive (help, history, Ctrl-R, TAB completion) or scripted, with table, line or JSON output. Start it with just a settings file: kafcacheql ~/.kafcacheql/cloud.properties
- Your own / commands: save the queries you run every day as SQL files with typed, optional arguments in ~/.kafcacheql/commands, then run them by name, e.g. /last shop-orders 30 (every record from the last 30 minutes) or /tail shop-orders 10. help shows each command's usage and SQL, and TAB completes command and topic names. Five examples ship with the repo
- follow: like tail -f for SQL. follow /last shop-orders reruns a query or command every second (or every N seconds, e.g. follow 0.5 ...) and prints only the rows it hasn't shown yet until Ctrl-C. Works with joins, and with --mode json it streams one JSON object per row, ready for jq
- SHOW TABLES, SHOW LAG, DESCRIBE, DROP TABLE (cache only) and SYNC, with wildcards like SHOW TABLES shop-* or SYNC shop-*, easy to run from cron to keep a cache warm
- A Docker web-store demo with Zeppelin charts to try it in minutes
Repo: https://github.com/ifnesi/kafcacheql
Note: the code and docs were written with the assistance of AI, with every change tested and reviewed before release.