|
1 | 1 | # KSQL
|
2 | 2 |
|
| 3 | +Spaws a kafka cluster including zookeeper and a ksqldb server. The traditional ksqldb-cli images is replaced with an own image as the traditional ksqldb-cli does not provide an arm image. |
| 4 | + |
3 | 5 | ```
|
4 | 6 | docker-compose up
|
5 | 7 | ```
|
6 | 8 |
|
| 9 | +After the containers of the docker-compose file are started, the following command can be used run the ksqldb client of the ksqldb-client container. |
| 10 | + |
7 | 11 | ```
|
8 | 12 | docker exec -it ksqldb-cli ksql http://ksqldb-server:8088
|
9 | 13 | ```
|
10 | 14 |
|
| 15 | +## Setup Instructions |
| 16 | + |
11 | 17 | https://github.com/confluentinc/ksql
|
12 | 18 |
|
13 | 19 | https://ksqldb.io/quickstart.html
|
| 20 | + |
| 21 | +## KSQL-CLI Image |
| 22 | + |
| 23 | +https://hub.docker.com/_/debian |
| 24 | + |
| 25 | +https://stackoverflow.com/questions/46032392/docker-compose-does-not-allow-to-use-local-images |
| 26 | + |
| 27 | +https://docs.ksqldb.io/en/latest/operate-and-deploy/installation/install-ksqldb-with-docker/#connect-ksqldb-cli-to-a-dockerized-ksqldb-server |
| 28 | + |
| 29 | +## KSQL Demo |
| 30 | + |
| 31 | +``` |
| 32 | +CREATE STREAM riderLocations (profileId VARCHAR, latitude DOUBLE, longitude DOUBLE) WITH (kafka_topic='locations', value_format='json', partitions=1); |
| 33 | +``` |
| 34 | + |
| 35 | +``` |
| 36 | +CREATE TABLE currentLocation AS |
| 37 | + SELECT profileId, |
| 38 | + LATEST_BY_OFFSET(latitude) AS la, |
| 39 | + LATEST_BY_OFFSET(longitude) AS lo |
| 40 | + FROM riderlocations |
| 41 | + GROUP BY profileId |
| 42 | + EMIT CHANGES; |
| 43 | +``` |
| 44 | + |
| 45 | +``` |
| 46 | +CREATE TABLE ridersNearMountainView AS |
| 47 | + SELECT ROUND(GEO_DISTANCE(la, lo, 37.4133, -122.1162), -1) AS distanceInMiles, |
| 48 | + COLLECT_LIST(profileId) AS riders, |
| 49 | + COUNT(*) AS count |
| 50 | + FROM currentLocation |
| 51 | + GROUP BY ROUND(GEO_DISTANCE(la, lo, 37.4133, -122.1162), -1); |
| 52 | +``` |
| 53 | + |
| 54 | +``` |
| 55 | +-- Mountain View lat, long: 37.4133, -122.1162 |
| 56 | +SELECT * FROM riderLocations |
| 57 | + WHERE GEO_DISTANCE(latitude, longitude, 37.4133, -122.1162) <= 5 EMIT CHANGES; |
| 58 | +``` |
| 59 | + |
| 60 | +``` |
| 61 | +INSERT INTO riderLocations (profileId, latitude, longitude) VALUES ('c2309eec', 37.7877, -122.4205); |
| 62 | +INSERT INTO riderLocations (profileId, latitude, longitude) VALUES ('18f4ea86', 37.3903, -122.0643); |
| 63 | +INSERT INTO riderLocations (profileId, latitude, longitude) VALUES ('4ab5cbad', 37.3952, -122.0813); |
| 64 | +INSERT INTO riderLocations (profileId, latitude, longitude) VALUES ('8b6eae59', 37.3944, -122.0813); |
| 65 | +INSERT INTO riderLocations (profileId, latitude, longitude) VALUES ('4a7c7b41', 37.4049, -122.0822); |
| 66 | +INSERT INTO riderLocations (profileId, latitude, longitude) VALUES ('4ddad000', 37.7857, -122.4011); |
| 67 | +``` |
| 68 | + |
| 69 | +``` |
| 70 | +SELECT * from ridersNearMountainView WHERE distanceInMiles <= 10; |
| 71 | +``` |
| 72 | + |
| 73 | +## KSQL Follow Up |
| 74 | + |
| 75 | +https://docs.ksqldb.io/en/latest/concepts/streams/ |
| 76 | + |
| 77 | +https://docs.ksqldb.io/en/latest/concepts/?_ga=2.59521449.545340244.1677833658-274482105.1677001988 |
| 78 | + |
| 79 | +## Q&A |
| 80 | + |
| 81 | +https://stackoverflow.com/questions/36249744/interactive-shell-using-docker-compose |
| 82 | + |
| 83 | +https://stackoverflow.com/questions/30233105/docker-compose-up-for-only-certain-containers |
| 84 | + |
| 85 | +https://stackoverflow.com/questions/31746182/docker-compose-wait-for-container-x-before-starting-y |
0 commit comments