进入正文前,感谢宝子们订阅专题、点赞、评论、收藏!关注IT贫道,获取高质量博客内容!
🏡个人主页:含各种IT体系技术,IT贫道_大数据OLAP体系技术栈,Apache Doris,Kerberos安全认证-CSDN博客
📌订阅:拥抱独家专题,你的订阅将点燃我的创作热情!
👍点赞:赞同优秀创作,你的点赞是对我创作最大的认可!
⭐️ 收藏:收藏原创博文,让我们一起打造IT界的荣耀与辉煌!
✏️评论:留下心声墨迹,你的评论将是我努力改进的方向!
博主个人B栈地址:豹哥教你大数据的个人空间-豹哥教你大数据个人主页-哔哩哔哩视频
目录
1. 文件数据源
2. MySQL数据源
1. 文件数据源
clickhouse中的字典还可以映射本地文件数据。操作如下:
1) 创建本地csv文件
在本地创建的csv文件需要放在“/var/lib/clickhouse/user_files”路径下,在此目录下创建organization.csv文件,写入如下内容:
1,"a0001","研发部"2,"a0002","产品部"3,"a0003","数据部"4,"a0004","测试部"5,"a0005","运维部"6,"a0006","规划部"7,"a0007","市场部"
2)创建字典表
#在clickhouse中创建字典表create dictionary org_dic(id UInt64,code String,name String)primary key idSOURCE(FILE(path '/var/lib/clickhouse/user_files/organization.csv' format 'CSV'))LAYOUT(FLAT())LIFETIME(30);注意:SOURCE(FILE(path '文件名',' 文件格式')),文件格式支持CSV和TabSeparated。#查询使用字典表node1 :) select dictGet('dic_test_db.org_dic','name',toUInt64(2)) as name;┌─name───┐│ 产品部 │└────────┘
2. MySQL数据源
clickhouse中还支持从MySQL中提取数据到字典表。具体操作如下:
1)在MySQL中创建表organization并插入数据
#在mysql中创建库、表及插入数据mysql> create database mytest;mysql> use mytest;mysql> create table organization(id int,code varchar(255),name varchar(255));#插入数据insert into mytest.organization values(1,"a0001","org1");insert into mytest.organization values(2,"a0002","org2");insert into mytest.organization values(3,"a0003","org3");insert into mytest.organization values(4,"a0004","org4");insert into mytest.organization values(5,"a0005","org5");insert into mytest.organization values(6,"a0006","org6");insert into mytest.organization values(7,"a0007","org7");#查询数据mysql> select * from organization;
2)在clickhouse中创建字典表
#在clickhouse中创建flat字典表create dictionary org_dic2(id UInt64,code String,name String)primary key idSOURCE(MYSQL(port 3306user 'root'password '123456'host 'node2'db 'mytest'table 'organization'))LAYOUT(FLAT())LIFETIME(MIN 3 MAX 5);#使用字典表node1 :) select dictGet('dic_test_db.org_dic2','name',toUInt64(2)) as name;┌─name─┐│ org2 │└──────┘
注意:clickhouse字典表除了支持将MySQL、clickhouse表作为数据来源,还可以从MongoDB中读取数据。
👨💻如需博文中的资料请私信博主。