首页 > 解决方案 > 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?

标签: clickhouse

解决方案


DDL 字典不能驻留在全局范围内,因为它在 DDL 方面不存在。

据我了解,您的问题是基于 xml 的字典和 DDL 的向后不兼容,因此修复它的一次方法是添加数据库前缀(例如,如果它在表模式中定义需要应用ALTER TABLE MODIFY COLUMN -陈述)。为了从基于 xml 的字典轻松迁移到基于 DDL 的字典,需要临时托管两种类型的字典(xml 和 DDL),并将所有消费者一一切换到 DDL 字典。


DDL 字典比基于 xml 的字典更易于维护和灵活,因为:


推荐阅读