continuous view 是 pipelinedb的核心,类似一个view,但是数据是合并了stream以及table的数据输入数据,并且是
实时根据输入数据进行更新的
CREATE CONTINUOUS VIEW name AS query
query是一个pg 的select 格式的语法,格式如下:
SELECT [ DISTINCT [ ON ( expression [, ...] ) ] ]
expression [ [ AS ] output_name ] [, ...]
[ FROM from_item [, ...] ]
[ WHERE condition ]
[ GROUP BY expression [, ...] ]
[ WINDOW window_name AS ( window_definition ) [, ...] ]
where from_item can be one of:
stream_name [ [ AS ] alias [ ( column_alias [, ...] ) ] ]
table_name [ [ AS ] alias [ ( column_alias [, ...] ) ] ]
from_item [ NATURAL ] join_type from_item [ ON join_condition ]
项目使用docker运行同时结合hasura graphql 引擎
version: '3.6'
services:
postgres:
image: pipelinedb/pipelinedb
ports:
- "5432:5432"
graphql-engine:
image: hasura/graphql-engine:v1.0.0-alpha06
ports:
- "8080:8080"
depends_on:
- "postgres"
command: >
/bin/sh -c "
graphql-engine --database-url postgres://pipeline:pipeline@postgres:5432/pipeline serve --enable-console;
"CREATE TABLE userlogin (
id SERIAL PRIMARY KEY,
username text NOT NULL,
userid integer NOT NULL,
usertype text NOT NULL,
logintype text NOT NULL
);
```
* 创建stream:
```code
CREATE STREAM loginlogs (logintype text, userid integer);CREATE CONTINUOUS VIEW userloginview AS
select a.logintype,b.username,b.userid, b.logintype as logintype_ from loginlogs a join userlogin b
on a.userid=b.userid
insert into loginlogs(logintype,userid) values ('mobile',333),('pc',333),('web',333)select * from userloginview


CREATE CONTINUOUS VIEW latency AS
SELECT percentile_cont(array[90, 95, 99]) WITHIN GROUP (ORDER BY latency)
FROM latency_stream;CREATE CONTINUOUS VIEW imps AS
SELECT COUNT(*) FROM imps_stream
WHERE (arrival_timestamp > clock_timestamp() - interval '5 minutes');来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69946831/viewspace-3135755/ ,如需转载,请注明出处,否则将追究法律责任。