Skip to content

Instantly share code, notes, and snippets.

@steve-chavez
Created September 19, 2018 13:38
Show Gist options
  • Save steve-chavez/3b797aa90fa809d2da49204af06a199a to your computer and use it in GitHub Desktop.
Save steve-chavez/3b797aa90fa809d2da49204af06a199a to your computer and use it in GitHub Desktop.
docker run -d -p 5433:5432 pipelinedb/pipelinedb:0.9.9
PGPASSWORD=pipeline psql -h localhost -p 5433 -U pipeline -d pipeline <<EOF
CREATE STREAM wiki_stream (hour timestamp, project text, title text, view_count bigint, size bigint);
CREATE CONTINUOUS VIEW wiki_stats AS
SELECT hour, project,
count(*) AS total_pages,
sum(view_count) AS total_views,
min(view_count) AS min_views,
max(view_count) AS max_views,
avg(view_count) AS avg_views,
percentile_cont(0.99) WITHIN GROUP (ORDER BY view_count) AS p99_views,
sum(size) AS total_bytes_served
FROM wiki_stream
GROUP BY hour, project;
EOF
curl -sL http://pipelinedb.com/data/wiki-pagecounts | gunzip | \
psql -h localhost -p 5433 -U pipeline -d pipeline -c "COPY wiki_stream (hour, project, title, view_count, size) FROM STDIN"
cat << EOF >> pgrst-pipeline.conf
db-uri = "postgres://pipeline@localhost:5433/pipeline"
db-schema = "public"
db-anon-role = "pipeline"
EOF
./postgrest pgrst-pipeline.conf
curl -s "http://localhost:3000/wiki_stats?order=hour.desc&limit=100"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment