clickhouse数据字典

news/2024/10/9 10:47:07/

前言:
clickhouse的安装见

https://blog.csdn.net/weixin_41463944/article/details/142534145?spm=1001.2014.3001.5501

1、需要在路径/etc/clickhouse-serve下定义*_dictionary.xml结尾的配置文件
2、需要准备organization.csv和sales.csv本地测试文件(注意不是windows下的xlsx表格,是linux下的文件)

2.1 organization.csv文件

1,"a0001","研发部"
2,"a0002","产品部"
3,"a0003","数据部"
4,"a0004","测试部"
5,"a0005","运维部"
6,"a0006","规划部",
7,"a0007","市场部"

2.2 sales.csv文件
1,2016-01-01,2017-01-10,100
2,2016-05-01,2017-07-01,200
3,2014-03-05,2018-01-20,300
4,2018-08-01,2019-10-01,400
5,2017-03-01,2017-06-01,500
6,2017-04-09,2018-05-30,600
7,2018-06-01,2019-01-25,700
8,2019-08-01,2019-12-12,800

3、关于每个xml字典文件的格式

<?xml version="1.0"?>
<dictionaries><dictionary><name>字典名称(全局唯一)</name><source>数据源配置</source><layout>字典数据在内存中的格式</layout><structure>字典的数据结构</structure><lifetime>字典的自动更新频率<min>300</min><max>360</max></lifetime></dictionary>
</dictionaries>

4、关于扩展字典的几种类型配置
一共7种类型,其中flat、hashed、sparse_hashed、range_hashed、cache的主键为数值型UInt64类型的,其他类型如complex_key_hashed、complex_key_cache为复合类型的key

4.1)flat类型的字典,在/etc/clickhouse-serve目录下新建test_flat_dictionary.xml
<?xml version="1.0"?>
<dictionaries><dictionary><name>test_flat_dict</name><source><file><path>/home/clickhouse-server/etc/clickhouse-server/dictionary/organization.csv</path><format>CSV</format></file></source><layout><flat/></layout><structure><id><name>id</name></id><attribute><name>code</name><type>String</type><null_value></null_value></attribute><attribute><name>name</name><type>String</type><null_value></null_value></attribute></structure><lifetime><min>300</min><max>360</max></lifetime></dictionary>
</dictionaries>
4.2)hashed类型的字典,在/etc/clickhouse-serve目录下新建test_hashed_dictionary.xml
<?xml version="1.0"?>
<dictionaries><dictionary><name>test_hashed_dict</name><source><file><path>/home/clickhouse-server/etc/clickhouse-server/dictionary/organization.csv</path><format>CSV</format></file></source><layout><hashed/></layout><structure><id><name>id</name></id><attribute><name>code</name><type>String</type><null_value></null_value></attribute><attribute><name>name</name><type>String</type><null_value></null_value></attribute></structure><lifetime><min>300</min><max>360</max></lifetime></dictionary>
</dictionaries>
4.3)complex_key_hashed类型的字典,在/etc/clickhouse-serve目录下新建complex_key_hashed_dictionary.xml
<?xml version="1.0"?>
<dictionaries><dictionary><name>test_complex_key_hashed_dict</name><source><file><path>/home/clickhouse-server/etc/clickhouse-server/dictionary/organization.csv</path><format>CSV</format></file></source><layout><complex_key_hashed/></layout><structure><key><attribute><name>id</name><type>UInt64</type></attribute><attribute><name>code</name><type>String</type></attribute></key><attribute><name>name</name><type>String</type><null_value></null_value></attribute></structure><lifetime><min>300</min><max>360</max></lifetime></dictionary>
</dictionaries>
4.4)range_hashed类型的字典,在/etc/clickhouse-serve目录下新建test_range_hashed_dictionary.xml
<?xml version="1.0"?>
<dictionaries><dictionary><name>test_range_hashed_dict</name><source><file><path>/home/clickhouse-server/etc/clickhouse-server/dictionary/sales.csv</path><format>CSV</format></file></source><layout><range_hashed/></layout><structure><id><name>id</name></id><range_min><name>start</name></range_min><range_max><name>end</name></range_max><attribute><name>price</name><type>Float32</type><null_value></null_value></attribute></structure><lifetime><min>300</min><max>360</max></lifetime></dictionary>
</dictionaries>

5、关于字典的数据源
5.1 文件类型,格式通常为CSV或者TabSeparated
1)本地文件

<source><file><path>/home/clickhouse-server/etc/clickhouse-server/dictionary/organization.csv</path><format>CSV</format></file></source>
2)可执行文件
<source><executable><command>/home/clickhouse-server/etc/clickhouse-server/dictionary/organization.csv</command><format>CSV</format></executable></source>
3)远程文件
<source><http><url>xxxxx.csv</url><format>CSV</format></http></source>
5.2 数据库类型的数据源
1)mysql
<source><mysql><port>3306</port><user>xxxx</user><password>xxxx</password><replica><host>localhost</host><priority>1</priority></replica><db>db_mybatis</db><table>userList</table></mysql></source>

其中<mysql> 标签的下一级可添加 <where>is_deleted=0</where>做为筛选条件
2)clickhouse

 <source><clickhouse><host>localhost</host><port>9000</port><user>xxxx</user><password>xxxxx</password><db>my_database</db><table>test_table</table></clickhouse></source>

6、关于DDL语句

dictGet(‘字典名称’,‘字典的具体字段’,‘key键值’),如果字典为复合key的话,则在字典函数中的key用元组tuple(‘a’,‘b’,‘c’)表示

7、关于手动刷新数据字典

7.1 )全局字典刷新

system reload dictionaries

7.2)刷新单个字典(字典名称不加单引号)

system reload dictionary test_mysql_dict

http://www.ppmy.cn/news/1536597.html

相关文章

【数据分享】2000—2023年我国省市县三级逐月植被覆盖度(FVC)数值(Shp/Excel格式)

之前我们分享过2000—2023年我国250米分辨率逐月植被覆盖度&#xff08;FVC&#xff09;栅格数据&#xff08;可查看之前的文章获悉详情&#xff09;&#xff0c;该数据来源于高吉喜等学者在国家青藏高原科学数据中心平台上分享的数据&#xff0c;合成方式采用月最大值合成&…

项目开发--大模型--个人问答知识库--chain控制

背景 1、langchain当中的chain prompt | llm | output_parser这个链能更长吗&#xff1f; 在 LangChain 中&#xff0c;链&#xff08;chain&#xff09;可以根据需要变得非常长&#xff0c;并且可以包含多种不同类型的组件。链的目的是将多个步骤串联起来&#xff0c;以便以…

如何在 SQL 中更新表中的记录?

当你需要修改数据库中已存在的数据时&#xff0c;UPDATE 语句是你的首选工具。 这允许你更改表中一条或多条记录的特定字段值。 下面我将详细介绍如何使用 UPDATE 语句&#xff0c;并提供一些开发建议和注意事项。 基础用法 假设我们有一个名为 employees 的表&#xff0c;…

【python进阶攻略12】C扩展

使用C扩展 CPython还为开发者实现了一个有趣的特性&#xff0c;使用Python可以轻松调用C代码 开发者有三种方法可以在自己的Python代码中来调用C编写的函数-ctypes&#xff0c;SWIG&#xff0c;Python/C API。每种方式也都有各自的利弊。 首先&#xff0c;我们要明确为什么要…

02_23 种设计模式之《抽象工厂模式》

文章目录 一、抽象工厂模式抽象工厂模式的结构应用场景 示例代码&#xff08;C&#xff09;注意事项 一、抽象工厂模式 抽象工厂模式&#xff08;Abstract Factory Pattern&#xff09;隶属于设计模式中的创建型模式&#xff0c;用于产品族的构建。抽象工厂是指当有多个抽象角…

mit6824-01-MapReduce详解

文章目录 MapReduce简述编程模型执行流程执行流程排序保证Combiner函数Master数据结构 容错性Worker故障Master故障 性能提升定制分区函数局部性执行缓慢的worker(slow workers) 常见问题总结回顾参考链接 MapReduce简述 MapReduce是一个在多台机器上并行计算大规模数据的软件架…

自旋锁深度解析:原理、实现与应用

在并发编程中,锁机制是确保多个线程或进程安全访问共享资源的关键。锁能够防止数据竞争和不一致性问题,从而保证程序的正确性和稳定性。在众多锁机制中,自旋锁(spin lock)以其独特的机制和高效的性能,在多线程编程中占据了重要地位。本文将深入探讨自旋锁的原理、实现以及…

UE4 材质学习笔记01(什么是着色器/PBR基础)

1.什么是shader 着色器是控制屏幕上每个像素颜色的代码&#xff0c;这些代码通常在图形处理器上运行。 现如今游戏引擎使用先进的基于物理的渲染和照明。而且照明模型模型大多数是被锁定的。 因此我们创建着色器可以控制颜色&#xff0c;法线&#xff0c;粗糙度&#xff0c;…