简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM