Without the LIMIT keyword, the SELECT query would run indefinitely until you stop it by pressing
SELECT pageid FROM pageviews_original LIMIT 3;
Page_59 Page_92 Page_37 Page_30 Page_69 Page_27
==== Persistent Query ====
Unlike the non-persistent query above,
* Results from this query are written to the Kafka topic PAGEVIEWS_FEMALE.
* Queries will continuously run as KSQL applications until they are manually terminated. Exiting KSQL does not terminate persistent queries.
The query below enriches the pageviews STREAM by doing a LEFT JOIN with the users_original TABLE on the user ID, where a condition is met.
CREATE STREAM pageviews_femaleASSELECTusers_original.userid AS userid, pageid, regionid, genderFROMpageviews_originalLEFT JOIN users_originalONpageviews_original.userid = users_original.useridWHEREgender = 'FEMALE';
Message
Stream created and running
SHOW STREAMS;
Stream Name | Kafka Topic | Format
PAGEVIEWS_ORIGINAL | pageviews | DELIMITEDPAGEVIEWS_FEMALE | PAGEVIEWS_FEMALE | DELIMITED
* See the result. Ctrl+c will terminate the output to the console but not the query.
SELECT * FROM pageviews_female;
Exiting KSQL does not terminate persistent queries.. They will continuously run as KSQL applications until they are manually terminated.
* Show
SHOW QUERIES;
Query ID | Kafka Topic | Query String
1 | PAGEVIEWS_FEMALE | CREATE STREAM pageviews_female AS SELECT users_original.userid AS userid, pageid, regionid, gender FROM
* Terminate the query. If you want to see the data flowing in the next section with a standard consumer, don't do that now but at the end.
TERMINATE 1
Message
Query terminated.
==== Create a persistent query with a window ====
CREATE TABLE user_timeview ASSELECTuserid, sum( viewtime ) AS numusersFROMpageviews_originalWINDOW TUMBLING( size 30 second )GROUP BYuserid;
* Get the data with Kafka - Consumer
docker-compose exec kafka binbashkafka-console-consumer –bootstrap-server localhost:29092 –topic PAGEVIEWS_FEMALE –max-messages 20
User_8,Page_15,Region_5,FEMALE User_5,Page_74,Region_3,FEMALE User_5,Page_39,Region_3,FEMALE User_5,Page_56,Region_3,FEMALE User_5,Page_60,Region_3,FEMALE User_5,Page_12,Region_3,FEMALE User_5,Page_73,Region_3,FEMALE User_8,Page_91,Region_2,FEMALE User_2,Page_87,Region_8,FEMALE User_7,Page_21,Region_3,FEMALE User_2,Page_59,Region_8,FEMALE User_7,Page_54,Region_9,FEMALE User_8,Page_62,Region_6,FEMALE User_7,Page_45,Region_9,FEMALE User_8,Page_69,Region_6,FEMALE User_8,Page_19,Region_6,FEMALE User_8,Page_32,Region_6,FEMALE User_2,Page_71,Region_8,FEMALE User_2,Page_83,Region_8,FEMALE User_8,Page_40,Region_1,FEMALE Processed a total of 20 messages
===== Client Server mode =====
From https://github.com/confluentinc/ksql/issues/272
Start one or more servers using the following command:
$ ./bin/ksql-server-start /path/to/ksql_server1.properties</code.A sample properties file is as follows:
Note that for each server you need a properties file and the listeners value should be unique.In a new terminal window start a cli and connect to one of the servers by passing it's listener address: