clickhouse简单使⽤+函数整理
⼀、DDL
如果想按集操作,需要借助zookeeper,在l中添加配置
<distributed_ddl>
/clickhouse/task_queue/ddl
</distributed_ddl>
⼀个节点创建表,会同步到各个节点
CREATE TABLE db.table [ON CLUSTER cluster] (…)
添加、删除、修改列
ALTER TABLE [db].table [ON CLUSTER cluster] ADD|DROP|MODIFY COLUMN …
rename ⽀持*MergeTree和Distributed
rename table db.table1 to db.table2 [ON CLUSTER cluster]
truncate table db.table;不⽀持Distributed引擎
⼆、delete/update 不⽀持Distributed引擎
ALTER TABLE [db.]table DELETE WHERE filter_expr…column函数的使用
ALTER TABLE [db.]table UPDATE column1 = expr1 [, …] WHERE …
三、分区表
按时间分区:
toYYYYMM(EventDate):按⽉分区
toMonday(EventDate):按周分区
toDate(EventDate):按天分区
按指定列分区:
PARTITION BY cloumn_name
对分区的操作:
alter table test1 DROP PARTITION [partition] #删除分区
alter table test1 DETACH PARTITION [partition]#下线分区
alter table test1 ATTACH PARTITION [partition]#恢复分区
alter table .test1 FREEZE PARTITION [partition]#备份分区
四、数据同步
1. 采⽤remote函数
insert into db.table select * from remote(‘⽬标IP’,db.table,‘user’,‘passwd’)
2. csv⽂件导⼊clickhouse
cat test.csv | clickhouse-client -u user --password password --query=“INSERT INTO db.table FORMAT CSV”
3. 同步mysql库中表
CREATE TABLE tmp ENGINE = MergeTree ORDER BY id AS SELECT * FROM mysql(‘hostip:3306’, ‘db’, ‘table’,‘user’, ‘passwd’) ;
4) clickhouse-copier ⼯具
五、时间戳转换
select toUnixTimestamp(‘2018-11-25 00:00:02’) --DateTime转化为时间戳
注意:可以指定时区,例如:select toUnixTimestamp(‘2018-11-25 00:00:02’,‘Asia/Shanghai’)
select toDateTime(1543075202) --时间戳转化为DateTime
select toDateTime(‘2018-04-30 00:00:00’) --转化为DateTime的标准格式
结果:2018-04-30T00:00:00+00:00
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论