ksql 使用

https://docs.ksqldb.io/en/latest/developer-guide/ksqldb-reference/

注意执行命令要在ksqldb-server 而不是 ksqldb-cli 的容器下面

stream 和 table 的区别是,table必须定义primary key,而且执行了query后下次还可以拿到数据,而stream是没有的

ksql> print bear from beginning;
 
CREATE STREAM pageviews_original (viewtime bigint, userid varchar, pageid varchar) WITH (kafka_topic='pageviews', value_format='DELIMITED');
 
CREATE TABLE users_original (registertime bigint primary key, gender varchar, regionid varchar, userid varchar) WITH (kafka_topic='users', value_format='JSON');
 
ksql> select * from USERS_ORIGINAL emit changes limit 5;

ksql> select * from users_original where rowtime >='2022-03-18' emit changes;

ksql> show queries;

stream 和 table都可以insert data

ksql> insert into stream_test values('1',1,1,1);

ksql> insert into users_original(REGISTERTIME,GENDER,REGIONID,USERID) values(1,'G1','G1','G1');

想count的话只能通过group by 的操作,数据量大的话会是个灾难

ksql> select key,count(*) from stream_test group by key emit changes;

 ksql> select count(*) from stream_test group by 1 emit changes;

可以用describe extended 命令查询
ksql> describe stream_test extended;

 

Oftentimes—and particularly in testing and development—you’ll want to read the data that already exists in a topic. To tell KSQL to do this, change the offset property:
ksql> SET 'auto.offset.reset'='earliest';
 

update table 的话可以通过join语法创建个新表来实现

posted on   白马酒凉  阅读(635)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 【.NET】调用本地 Deepseek 模型
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 我与微信审核的“相爱相杀”看个人小程序副业
历史上的今天:
2020-03-19 SoapUI 使用 JDBC Request
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

导航

点击右上角即可分享
微信分享提示