备注: 使用docker 模式进行安装
1. 准备docker 环境(需要docker-compose)
docker的安装不需要进行多描述了,直接yum或者源码编译也可以
2. 安装 kafa 以及ksql
[email protected]:confluentinc/ksql.git
cdksql/docs/quickstart/
docker-composeup-d
3. 启动使用
docker-composeexecksql-cliksql-clilocal--bootstrap-serverkafka:29092
参考界面:
4. 使用
创建示例
a. 非持久化数据查询
创建测试使用的表
CREATESTREAMpageviews_original(viewtimebigint,useridvarchar,pageidvarchar)WITH(kafka_topic='pageviews',value_format='DELIMITED');
DESCRIBEpageviews_original;
CREATETABLEusers_original(registertimebigint,gendervarchar,regionidvarchar,useridvarchar)WITH(kafka_topic='users',value_format='JSON');
DESCRIBEusers_original;
显示系统的stream
SHOWSTREAMS;
StreamName|KafkaTopic|Format
----------------------------------------------
PAGEVIEWS_ORIGINAL|pageviews|DELIMITED
显示系统的表
SHOWTABLES;
TableName|KafkaTopic|Format|Windowed
--------------------------------------------------
USERS_ORIGINAL|users|JSON|false
查询数据
SELECTpageidFROMpageviews_originalLIMIT3;
Page_66
Page_17
Page_67
LIMITreachedforthepartition.
Queryterminated
b. 持久化数据查询
创建数据
CREATESTREAMpageviews_femaleASSELECTusers_original.useridASuserid,pageid,regionid,genderFROMpageviews_originalLEFTJOINusers_originalONpageviews_original.userid=users_original.useridWHEREgender='FEMALE';
DESCRIBEpageviews_female;
Field|Type
----------------------------
ROWTIME|BIGINT
ROWKEY|VARCHAR(STRING)
USERID|VARCHAR(STRING)
PAGEID|VARCHAR(STRING)
REGIONID|VARCHAR(STRING)
GENDER|VARCHAR(STRING)
查询数据
SELECT*FROMpageviews_female;
1504252783201|User_5|User_5|Page_49|Region_8|FEMALE
1504252783525|User_6|User_6|Page_39|Region_6|FEMALE
1504252783813|User_5|User_5|Page_15|Region_8|FEMALE
1504252789309|User_6|User_6|Page_90|Region_5|FEMALE
1504252792424|User_8|User_8|Page_40|Region_1|FEMALE
1504252796605|User_4|User_4|Page_12|Region_8|FEMALE
1504252797405|User_3|User_3|Page_22|Region_3|FEMALE
1504252802099|User_6|User_6|Page_43|Region_7|FEMALE
5. 支持的模式
表、持久化表、like、join、limit、tumblingwindow、简单聚合函数,目前来说还是比较强大的
6. 参考资料
https://github.com/confluentinc/ksql/tree/0.1.x/docs/quickstart
https://github.com/confluentinc/ksql/blob/0.1.x/docs/quickstart/quickstart-docker.md#docker-setup-for-ksql