Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create ksql table from ksql stream?

I'm a new bee to ksql. I'm just playing with read kafka topics to streams and it works great.

Also, trying to create a table from kafka topic and failed. Realized that I need to have a key set in kafka topic which is considered as primary key in ksql table. So I tried creating table from stream instead, but failed too. Query/Script:

CREATE TABLE DETAILS_TABLE AS SELECT SEQ, Server1, ServerId, NumberUri, SERVERID2, SERVER2 FROM details_stream WINDOW TUMBLING (SIZE 1 MINUTES);
Invalid result type. Your SELECT query produces a STREAM. Please use CREATE STREAM AS SELECT statement instead.

Can someone explain if its possible or not? If yes, wher am I going wrong? Thanks.

like image 438
srikanth Avatar asked May 05 '18 17:05

srikanth


People also ask

Can we query data from Kafka?

When navigating to a Kafka topic, you can query all existing data and the live stream. Lenses immediately presents a snapshot of the latest data in table browsing mode allowing: To Filter by timestamp, offset or partition. To Drill into the data and expand the key and value payloads and any nested fields.

Is KSQL production ready?

KSQL is ready for production use, and integrated into CP.

Is KSQL and ksqlDB same?

For the purposes of this topic, "ksqlDB" refers to ksqlDB 0.6. 0 and beyond, and "KSQL" refers to all previous releases of KSQL (5.3 and lower). ksqlDB is not backward compatible with previous versions of KSQL. This means that, ksqlDB doesn't run over an existing KSQL deployment.


1 Answers

As Matthias says, you need to specify a (valid) aggregate query.

So this would work:

CREATE TABLE DETAILS_TABLE AS \
SELECT SEQ, Server1, ServerId, NumberUri, SERVERID2, SERVER2, COUNT(*) AS TOTAL \
FROM details_stream WINDOW TUMBLING (SIZE 1 MINUTES) \
GROUP BY SEQ, Server1, ServerId, NumberUri, SERVERID2, SERVER2;

Just as any SQL dialect, if you are doing an aggregation, you have to GROUP BY all of the fields, otherwise it makes no syntactical sense.

like image 57
Robin Moffatt Avatar answered Sep 24 '22 15:09

Robin Moffatt