Reputation: 173
I have a kafka cluster running locally and a topic named "my-topic" in which im pushing data. I also have the ksql server running and the query: SELECT*FROM "my-topic" gives me "my-topic does not exist". I understand that this query is not right and i would like to know if there is another way to query a topic.
Upvotes: 2
Views: 1279
Reputation: 15067
the query: SELECT*FROM "my-topic" gives me "my-topic does not exist"
You can't do a SELECT directly against a Kafka topic in KSQL -- the only two statements in KSQL that allow you to work directly against topics are (1) PRINT <topic_name>
and (2) SHOW TOPICS
.
Instead, you need to create streams (CREATE STREAM
) and/or create tables (CREATE TABLE
) in KSQL, whose input data will be read and parsed from the desired Kafka topic. Think of streams and tables in KSQL as "Kafka topics with a schema" (see my recent write-up Of Streams and Tables in Kafka and Stream Processing, Part 1 for more information).
Example:
CREATE STREAM pageviews (viewtime BIGINT, userid VARCHAR, ...)
WITH (KAFKA_TOPIC='pageviews-topic', \
VALUE_FORMAT='DELIMITED');
Upvotes: 3