clickhouse - Clickhouse Dictionaries: why CREATE DICTIONARY needs a database?
问题描述
The new CREATE DICTIONARY idiom in ClickHouse will create the dictionary inside a database:
CREATE DICTIONARY [IF NOT EXISTS] [db.]dictionary_name [ON CLUSTER cluster]
Dictionaries created by XML file are created as empty-string database:
<dictionaries>
<dictionary>
<name>rates</name>
<source>
...
</dictionaries>
and they generate an entry on system.dictionaries like this:
:) select * from system.dictionaries \G
...
Row 4:
──────
database:
name: rates
which is empty-string database, that is understood as a global dictionary that can be referred to without a database prefix.
However, with the CREATE DICTIONARY
SQL idiom, if db
is not specified, the DICTIONARY is created in the default
database, no as a global dictionary:
:) CREATE DICTIONARY IF NOT EXISTS rates (...)
:) select * from system.dictionaries \G
Row 2:
──────
database: default
name: rates
Question: Is there a way to create a global dictionary via SQL idiom?
解决方案
DDL 字典不能驻留在全局范围内,因为它在 DDL 方面不存在。
据我了解,您的问题是基于 xml 的字典和 DDL 的向后不兼容,因此修复它的一次方法是添加数据库前缀(例如,如果它在表模式中定义需要应用ALTER TABLE MODIFY COLUMN -陈述)。为了从基于 xml 的字典轻松迁移到基于 DDL 的字典,需要临时托管两种类型的字典(xml 和 DDL),并将所有消费者一一切换到 DDL 字典。
DDL 字典比基于 xml 的字典更易于维护和灵活,因为:
- 无需接触 xml 文件即可轻松管理它们(添加、删除等)
- ON CLUSTER -clause 允许在指定集群的所有服务器上执行某些操作
- 管理访问权限
- 从v20.4.2.9 开始,2020-05-12字典可以在 JOIN 子句而不是dictGet中有效使用(参见Altinity: Clickhouse Dictionaries Reloaded)
- 将其用作序数表
推荐阅读
- vba - 在 AutoExec 宏中使用“打开表单”打开表单时,Ms Access 2002 表单文本框和复选框将不起作用
- python - 从现有 JSON 中复制一些 k,v 以在 Python 中构成另一个 JSON
- python - 如何根据条件从特定点反转累积计数,然后在熊猫数据框中恢复计数?
- reactjs - 反应打字稿'='预期。TS1005
- firebase - 当来自streamBuilder的数据为空[]时如何显示特定的小部件?
- r - 使用 igraph 和 assortnet 在 R 中“手动”计算加权网络的 Newman Q、Q max 和分类系数
- sass - SASS - @use/@forward 和外部样式表
- typescript - getServerSideProps 上的 Supbase 策略 - Next.js
- android - 是否可以在不重新编译的情况下使科尔多瓦应用程序可调试?
- trusted-web-activity - 是否可以为同一域的不同页面创建多个 TWA 应用程序?