Skip to content

Commit 5b32200

Browse files
committed
[hackernews demo] run a sql after proton starts
1 parent e211a35 commit 5b32200

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

example/bytewax/compose.yaml

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
11
services:
2+
23
proton:
34
image: ghcr.io/timeplus-io/proton:latest
45
pull_policy: always
56
ports:
67
- 8463:8463
78
- 3218:3218
9+
volumes:
10+
- ./init_sql:/docker-entrypoint-initdb.d
811
healthcheck:
9-
test: ["CMD", "curl", "http://localhost:3218/proton/ping"]
10-
interval: 2s
12+
test: wget --no-verbose --tries=1 --spider http://localhost:8123/?query=show+create+comment || exit 1
13+
interval: 5s
1114
timeout: 10s
1215
retries: 3
13-
start_period: 10s
14-
init-proton:
15-
image: ghcr.io/timeplus-io/proton:latest
16-
command:
17-
- sh
18-
- -c
19-
- |
20-
proton-client -h proton -n --query "CREATE STREAM IF NOT EXISTS hn_stories_raw(raw string);CREATE STREAM IF NOT EXISTS hn_comments_raw(raw string);CREATE MATERIALIZED VIEW IF NOT EXISTS hn_stories AS SELECT to_time(raw:time) AS _tp_time,raw:id::int AS id,raw:title AS title,raw:by AS by, raw FROM hn_stories_raw;CREATE MATERIALIZED VIEW IF NOT EXISTS hn_comments AS SELECT to_time(raw:time) AS _tp_time,raw:id::int AS id,raw:root_id::int AS root_id,raw:by AS by, raw FROM hn_comments_raw;CREATE VIEW IF NOT EXISTS story AS SELECT * FROM hn_stories WHERE _tp_time>earliest_ts();CREATE VIEW IF NOT EXISTS comment AS SELECT * FROM hn_comments WHERE _tp_time>earliest_ts();"
21-
depends_on:
22-
proton:
23-
condition: service_healthy
16+
start_period: 15s
17+
2418
hn_stream:
2519
build:
2620
context: .
2721
image: timeplus/hackernews_bytewax:latest
2822
environment:
2923
- PROTON_HOST=proton
3024
depends_on:
31-
init-proton:
32-
condition: service_completed_successfully
25+
proton:
26+
condition: service_healthy
27+
3328
grafana:
3429
image: grafana/grafana:latest
3530
pull_policy: always
@@ -42,6 +37,4 @@ services:
4237
volumes:
4338
- ./grafana_provisioning:/etc/grafana/provisioning
4439
depends_on:
45-
- proton
46-
47-
40+
- proton

example/bytewax/init_sql/init.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CREATE STREAM IF NOT EXISTS hn_stories_raw(raw string);
2+
3+
CREATE STREAM IF NOT EXISTS hn_comments_raw(raw string);
4+
5+
CREATE MATERIALIZED VIEW IF NOT EXISTS hn_stories AS
6+
SELECT to_time(raw:time) AS _tp_time,raw:id::int AS id,raw:title AS title,raw:by AS by, raw FROM hn_stories_raw;
7+
8+
CREATE MATERIALIZED VIEW IF NOT EXISTS hn_comments AS
9+
SELECT to_time(raw:time) AS _tp_time,raw:id::int AS id,raw:root_id::int AS root_id,raw:by AS by, raw FROM hn_comments_raw;
10+
11+
CREATE VIEW IF NOT EXISTS story AS SELECT * FROM hn_stories WHERE _tp_time>earliest_ts();
12+
13+
CREATE VIEW IF NOT EXISTS comment AS SELECT * FROM hn_comments WHERE _tp_time>earliest_ts();

0 commit comments

Comments
 (0)