https://blog.csdn.net/liuxiangke0210/article/details/74010951

https://yq.aliyun.com/articles/166

一、pipelineDB默认的用户不是postgres而是pipeline。

pipeline=# \c
You are now connected to database "pipeline" as user "steven".

  

进入数据库 命令:pipeline  pipeline

[steven@steven1 ~]$ pipeline pipeline
pipeline (9.5.3)
Type "help" for help. pipeline=#

  

创建一个流 stream,一个stream就是一个FDW,其实不存储任何数据。

pipeline=# create stream stream_test(x integer, y integer, z text);
CREATE FOREIGN TABLE

查看流结构

pipeline=# \d stream_test;
Foreign table "public.stream_test"
Column | Type | Modifiers | FDW Options
-------------------+--------------------------+-----------+-------------
x | integer | |
y | integer | |
z | text | |
arrival_timestamp | timestamp with time zone | |
Server: pipelinedb

  

  

创建一个CONTINUOUS 连续视图

pipeline=# create continuous view v_sum as select sum (x + y) from stream_test;
CREATE VIEW
pipeline=# create continuous view v_group as select count(*) as coun,x,y,z from stream_test group by x,y,z;
CREATE VIEW

pipeline=# create continuous view v_single as select x,z from stream_test;
CREATE VIEW

  

  

stream 只能被continuous查询,如果直接查询会报错,被告知只能被continous view读取。

查看continues  views结构

pipeline=# \d v_group
View "public.v_group"
Column | Type | Modifiers
--------+---------+-----------
coun | bigint |
x | integer |
y | integer |
z | text |
pipeline=# \d v_single
View "public.v_single"
Column | Type | Modifiers
--------+---------+-----------
x | integer |
z | text |

  

创建好continuous,会附带创建一些别的东西。

pipeline=# \d
List of relations
Schema | Name | Type | Owner
--------+------------------+---------------+--------
public | v | view | steven
public | v_group | view | steven
public | v_group_mrel | table | steven
public | v_group_osrel | foreign table | steven
public | v_group_seq | sequence | steven
public | v_mrel | table | steven
public | v_osrel | foreign table | steven
public | v_seq | sequence | steven
public | v_single | view | steven
public | v_single_mrel | table | steven
public | v_single_osrel | foreign table | steven
public | v_single_seq | sequence | steven
public | v_sum | view | steven
public | v_sum_mrel | table | steven
public | v_sum_osrel | foreign table | steven
public | v_sum_seq | sequence | steven
(34 rows)

v_group  这个跟数据库中普通的View很类似,不存储任何东西,可以把他理解成一个materialized view,并且是非常高吞吐量,realtime的物化视图。

*_mrel,这个就是存储具体数据的,跟pg中的物理表是一样一样的。上面的cv就是这个物理表的一个壳子,不过这个物理表存储的内容可能是HLL格式。

*_seq,这个是给物理表创建的一个PK,看看cv_mrel发现默认会有个$pk字段。

*cv_osrel  这个是internal relation representing an output stream

插入数据到stream

pipeline=# insert into stream_test (x,y,z) values(1,2,'a'),(3,4,'b'),(5,6,'c'),(7,8,'d'),(1,2,'a');
INSERT 0 5

  

查询

pipeline=# select * from v_sum;
sum
-----
39
(1 row) pipeline=# select * from v_group;
coun | x | y | z
------+---+---+---
1 | 7 | 8 | d
1 | 5 | 6 | c
2 | 1 | 2 | a
1 | 3 | 4 | b
(4 rows)
pipeline=# select * from v_group_mrel;
coun | x | y | z | $pk
------+---+---+---+-----
1 | 7 | 8 | d | 1
1 | 5 | 6 | c | 2
2 | 1 | 2 | a | 3
1 | 3 | 4 | b | 4
(4 rows)

cv跟cv_mrel只是多了个$pk,这是在普通情况下,数据是这样的,如果做agg可能数据存储为HLL格式.

滑动窗口

我们来看看滑动窗口,在流计算中,窗口是个很重要的东西,例如最近5分钟,最近1小时,最近1天的汇总。  

1、创建一个流,列名time,数据类型timestamp;

pipeline=# create stream sliding (time timestamp);

  

2、创建一个滑动窗口(流动视图)

pipeline=# create continuous view cv_sliding with(sw='1 minute') as select time from sliding;
CREATE VIEW

  

3、插入一条当前时间数据

pipeline=# insert into sliding(time) values(now());
INSERT 0 1

  

4、查询

pipeline=# select * from cv_sliding;
time
----------------------------
2018-05-18 08:46:58.771057
(1 row)

  

5、过一会再插入两条时间数据,再次查询

pipeline=# insert into sliding(time) values(now());
INSERT 0 1
pipeline=# insert into sliding(time) values(now());
INSERT 0 1

  

pipeline=# select * from cv_sliding;
time
----------------------------
2018-05-18 08:46:58.771057
2018-05-18 08:47:22.253052
2018-05-18 08:47:29.265144
(3 rows)

  可以看到三条数据

6、过一会查询,少了一条,再过一会全部消失

pipeline=# select * from cv_sliding;
time
----------------------------
2018-05-18 08:47:22.253052
2018-05-18 08:47:29.265144
(2 rows)

  

pipeline=# select * from cv_sliding;
time
------
(0 rows)

  

ttl功能

pipeline=# create continuous view v_ttl with (ttl = '10 minute',ttl_column= 'minute') as select minute(arrival_timestamp), count(*) from sliding group by minute;
CREATE VIEW

  

pipeline=# insert into sliding values(now());
INSERT 0 1
pipeline=# insert into sliding values(now());
INSERT 0 1
pipeline=# insert into sliding values(now());
INSERT 0 1
pipeline=# insert into sliding values(now());
INSERT 0 1 pipeline=# select * from v_ttl;
minute | count
------------------------+-------
2018-05-18 09:04:00+00 | 4

  

pipeline=# insert into sliding values(now());
INSERT 0 1
pipeline=# select * from v_ttl;
minute | count
------------------------+-------
2018-05-18 09:04:00+00 | 4
2018-05-18 09:06:00+00 | 1
(2 rows)

  

transform

1、创建流和相对应的流动视图

pipeline=# create stream str1(x bigint,y text,z timestamp);
CREATE FOREIGN TABLE
pipeline=# create stream str2(x bigint,y text,z timestamp);
CREATE FOREIGN TABLE
pipeline=# create continuous view cv_1 as select x,y,z from str1;
CREATE VIEW
pipeline=# create continuous view cv_2 as select x,y,z from str2;
CREATE VIEW
pipeline=#

  

2、创建transform

pipeline=# create continuous transform tran_1 as select x,y,z from str1 then execute procedure pipeline_stream_insert('str2');
CREATE VIEW
pipeline=# insert into str1(x,y,z) values(1,'hi,i from str1',now());
INSERT 0 1
pipeline=# select * from cv_1;
x | y | z
---+----------------+---------------------------
1 | hi,i from str1 | 2018-05-18 09:21:01.11329
(1 row) pipeline=# select * from cv_2;
x | y | z
---+----------------+---------------------------
1 | hi,i from str1 | 2018-05-18 09:21:01.11329
(1 row)

  

在创建Transform用到的pipeline_stream_insert是PipelineDB自己提供的一个函数,这个我们可以自己定义一个函数。

pipeline=# create table t(x bigint,y text,z timestamp);

CREATE TABLE

pipeline=# CREATE OR REPLACE FUNCTION insert_into_t()

pipeline-#   RETURNS trigger AS

pipeline-#   $$

pipeline$#   BEGIN

pipeline$#     INSERT INTO t (x, y,z) VALUES (NEW.x, NEW.y,NEW.z);

pipeline$#     RETURN NEW;

pipeline$#   END;

pipeline$#   $$

pipeline-#   LANGUAGE plpgsql;

CREATE FUNCTION

pipeline=# CREATE CONTINUOUS TRANSFORM tran_t AS

pipeline-#   SELECT x,y,z FROM str1

pipeline-#   THEN EXECUTE PROCEDURE insert_into_t();

CREATE CONTINUOUS TRANSFORM

pipeline=# insert into str1(x,y,z) values(10,'I want insert table t',now());

INSERT 0 1

pipeline=# select * from t;

 x  |           y           |             z

----+-----------------------+---------------------------

 10 | I want insert table t | 2017-05-15 14:01:48.17516

(1 row)

自己写了一个trigger,然后把数据插入到表T中。

  

pipelinedb--流、滑动窗口测试的更多相关文章

  1. ASP.NET Core中使用滑动窗口限流

    滑动窗口算法用于应对请求在时间周期中分布不均匀的情况,能够更精确的应对流量变化,比较著名的应用场景就是TCP协议的流量控制,不过今天要说的是服务限流场景中的应用. 算法原理 这里假设业务需要每秒钟限流 ...

  2. pipelinedb 滑动窗口

    滑动窗口可以方便的让我们进行一段时间的数据分析 几个主要函数 clock_timestamp 内置的函数,总是返回当前的时间戳 arrival_timestamp 事件达到的时间 单滑动窗口 参考 C ...

  3. TCP通过滑动窗口和拥塞窗口实现限流,能抵御ddos攻击吗

    tcp可以通过滑动窗口和拥塞算法实现流量控制,限制上行和下行的流量,但是却不能抵御ddos攻击. 限流只是限制访问流量的大小,是无法区分正常流量和异常攻击流量的. 限流可以控制本软件或者应用的流量大小 ...

  4. TCP/IP 协议中的滑动窗口

    一个例子明白发送缓冲区.接受缓冲区.滑动窗口协议之间的关系. 在上面的几篇文章中简单介绍了上述几个概念在TCP网络编程中的关系,也对应了几个基本socket系统调用的几个行为,这里再列举一个例子,由于 ...

  5. 端口状态 LISTENING、ESTABLISHED、TIME_WAIT及CLOSE_WAIT详解,以及三次握手四次挥手,滑动窗口(整理转发)

    网上查了一下端口状态的资料,我下面总结了一下,自己学习学习: TCP状态转移要点 TCP协议规定,对于已经建立的连接,网络双方要进行四次握手才能成功断开连接,如果缺少了其中某个步骤,将会使连接处于假死 ...

  6. TCP 三次握手四次挥手, ack 报文的大小.tcp和udp的不同之处、tcp如何保证可靠的、tcp滑动窗口解释

    一.TCP三次握手和四次挥手,ACK报文的大小 首先连接需要三次握手,释放连接需要四次挥手 然后看一下连接的具体请求: [注意]中断连接端可以是Client端,也可以是Server端. [注意] 在T ...

  7. tcp协议头窗口,滑动窗口,流控制,拥塞控制关系

    参考文章 TCP 的那些事儿(下) http://coolshell.cn/articles/11609.html tcp/ip详解--拥塞控制 & 慢启动 快恢复 拥塞避免 http://b ...

  8. tcp的精髓:滑动窗口

    TCP协议作为一个可靠的面向流的传输协议,其可靠性和流量控制由滑动窗口协议保证,而拥塞控制则由控制窗口结合一系列的控制算法实现.一.滑动窗口协议 关于这部分自己不晓得怎么叙述才好,因为理解的部分更多, ...

  9. TCP 滑动窗口和 拥塞窗口

    转http://coolshell.cn/articles/11609.html 滑动窗口 -- 表征发送端和接收端的接收能力 拥塞窗口-- 表征中间设备的传输能力 TCP滑动窗口 需要说明一下,如果 ...

随机推荐

  1. 用jquery制作一个二级导航下拉菜单

    1使用$(function(){...})获取到想要作用的HTML元素. 2通过使用children()方法寻找子元素.       3通过使用show()方法来显示HTML元素.       4通过 ...

  2. noip第23课作业

    1.   营救 铁塔尼号遇险了!他发出了求救信号.距离最近的哥伦比亚号收到了讯息,时间就是生命,必须尽快赶到那里. 通过侦测,哥伦比亚号获取了一张海洋图.这张图将海洋部分分化成n*n个比较小的单位,其 ...

  3. POJ2229 Sumsets

    Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 19024   Accepted: 7431 Descrip ...

  4. hdu 1576 A/B 【扩展欧几里德】

    题目 A/9973=n 那么:n= A - A / 9973 * 9973   --① 设:A/B=x  则A=B*x,代入①  得  n=B*x-A/9973*9973 然后这个方程中的A/9973 ...

  5. 最大流最小割学习 基本知识 | 证明 | FF算法

    可行流 : 能流过去就行,不一定是最大流. 最大流:能流到的最大流量.(可能不只一个) 解决最大流: Ford-Fulkerson方法 最小割:从图中去除一些边,使得源点S到汇点T不连通,去除的这些边 ...

  6. 1.虚拟机中安装ubuntu

    1.VMware安装很简单,全部默认安装即可. 2.安装完VMware之后,打开VMware,点击创建虚拟机 典型安装易出问题,所以这里选择自定义安装 安装过程选项配置如下 处理器数,核数,内存都可以 ...

  7. 调用GOOGLE的TTS实现文字转语音(XE7+小米2)(XE10.1+小米5)

    相关资料: 注意:在手机上必须选安装文字转语音引擎“google Text To Speech”地址:http://www.shouji56.com/soft/GoogleWenZiZhuanYuYi ...

  8. ubuntu 安装CUDA 8.0

    安装CUDA 8.0 1) 在终端运行指令 sudo sh cuda_8.0.44_linux.run --no-opengl-libs 不加这个选项会进入循环登陆 2) 之后是一些提示信息,输入ac ...

  9. 开机或联网时自启动gunicorn

    网站部署完后,如果每次使用gunicorn启动网站会很麻烦,因此必须使gunicorn自启动. 环境 ubuntu 16. 参考: http://www.yangfan.cc/zhanzhang/14 ...

  10. C/C++掌握技能(一)

    1.在编译器中输入代码并将其保存为.cpp文件(C语言的文件扩展名.c,但为了使用C++中的一些好用的特性,请把文件扩展名改为C++的.cpp)2.等价头文件:#include<stdio.h& ...