pipelinedb 1.0.0 已经是一个标准的pg 扩展了,同时以前的语法也有变动,但是集成进hasura-graphql 更方便了
使用docker-compose 运行
环境准备
- docker-compose 文件
version: "3"
services:
db:
image: dalongrong/pipelinedb:1.0.0
environment:
- "POSTGRES_PASSWORD=dalongdemo"
ports:
- "5432:5432"
graphql-engine:
image: hasura/graphql-engine:v1.0.0-alpha25
ports:
- "8080:8080"
environment:
- "POSTGRES_PASSWORD:dalongdemo"
command: >
/bin/sh -c "
graphql-engine --database-url postgres://postgres:dalongdemo@db/postgres serve --enable-console;
"
- 创建pipelinedb stream 数据模型
CREATE FOREIGN TABLE wiki_stream (
hour timestamp,
project text,
title text,
view_count bigint,
size bigint)
SERVER pipelinedb;
CREATE VIEW wiki_stats WITH (action=materialize) 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;
添加数据
- insert 数据
可以使用官方的demo(数据比较大,有点慢)
curl -sL http://pipelinedb.com/data/wiki-pagecounts | gunzip | \
psql -c "
COPY wiki_stream (hour, project, title, view_count, size) FROM STDIN"
或者直接insert
INSERT INTO wiki_stream (hour,project,title,view_count,size)
VALUES ('2015-07-05 9:00:00','rong','bbb',4,100)
说明: 可以多添加几条数据
配置graphql
添加add 就可以了,新的比以前的更明确了,直接就是view 的明称
- add graphql
- 查询
说明
使用新的还是比较方便的,同时集成起来也更清晰了
参考资料
http://docs.pipelinedb.com/index.html
https://github.com/rongfengliang/pipelinedb-hasura-graphql