赞
踩
ClickHouse消费Kafka
Using the Kafka table engine | ClickHouse Docs
这里演示的是json数据
- CREATE TABLE 库名.kafka 对应表名
- (
- `msg` String
- )
- ENGINE = Kafka
- SETTINGS kafka_broker_list =
- 'xxxx:端口', kafka_topic_list = '主题', kafka_group_name = '消费者组', kafka_format = 'JSONAsString',kafka_num_consumers = 3;
创建物化视图的实体表,它的作用就是,如果没有它,那么创建出来的物化视图的实体表是一张隐藏的表,自己创建对应的表比较好管理。
- CREATE TABLE default.jielong_team_mp_message
- (
- `字段` String COMMENT '注解',
- `字段` String COMMENT '注解',
- `字段` String COMMENT '注解',
- `字段` String COMMENT '注解',
- `字段` String COMMENT '注解',
- `字段` String COMMENT '注解',
- `字段` String COMMENT '注解',
- `字段` String COMMENT '注解',
- `字段` String COMMENT '注解',
- `字段` String COMMENT '注解'
- )
- ENGINE = MergeTree
- PARTITION BY DATE(字段)
- ORDER BY (字段, 字段)
- SETTINGS index_granularity = 8192, storage_policy = '分区策略';
创建物化视图,并指定存储的实体表
- CREATE MATERIALIZED VIEW 库名.表名
- TO default.对应第二步的实体表
- (
- `字段` UInt64,
- `字段` UInt64,
- `字段` UInt64,
- `字段` UInt64,
- `字段` UInt64,
- `字段` UInt64,
- `字段` UInt64,
- `字段` UInt64,
- `字段` UInt64,
- `字段` UInt64
- )
- AS
- SELECT JSONExtract(msg, '字段', 'UInt64') AS 字段,
- JSONExtract(msg, '字段', 'UInt64') AS 字段,
- JSONExtract(msg, '字段', 'UInt64') AS 字段,
- JSONExtract(msg, '字段', 'UInt64') AS 字段,
- JSONExtract(msg, '字段', 'UInt64') AS 字段,
- JSONExtract(msg, '字段', 'UInt64') AS 字段,
- JSONExtract(msg, '字段', 'UInt64') AS 字段,
- JSONExtract(msg, '字段', 'UInt64') AS 字段,
- JSONExtract(msg, '字段', 'UInt64') AS 字段,
- JSONExtract(msg, '字段', 'UInt64') AS 字段
- FROM 库名.对应kafka表名;
直接删除就行,这里的删除表不会影响实际的主题
drop table
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。