Help wanted!

The following content of this documentation page has been machine-translated. But unlike other websites, it is not done on the fly. This translated text lives on GitHub repository alongside main ClickHouse codebase and waits for fellow native speakers to make it more human-readable. You can also use the original English version as a reference.

Help ClickHouse documentation by editing this page

分层字典

ClickHouse支持分层字典与 数字键.

看看下面的层次结构:

  1. 0 (Common parent)
  2. ├── 1 (Russia)
  3. └── 2 (Moscow)
  4. └── 3 (Center)
  5. └── 4 (Great Britain)
  6. └── 5 (London)

这种层次结构可以表示为下面的字典表。

region_idparent_regionregion_name
10俄罗斯
21莫斯科
32中心
40英国
54伦敦

此表包含一列 parent_region 包含该元素的最近父项的键。

ClickHouse支持 等级 属性为 外部字典 属性。 此属性允许您配置类似于上述的分层字典。

独裁主义 函数允许您获取元素的父链。

对于我们的例子,dictionary的结构可以是以下内容:

  1. <dictionary>
  2. <structure>
  3. <id>
  4. <name>region_id</name>
  5. </id>
  6. <attribute>
  7. <name>parent_region</name>
  8. <type>UInt64</type>
  9. <null_value>0</null_value>
  10. <hierarchical>true</hierarchical>
  11. </attribute>
  12. <attribute>
  13. <name>region_name</name>
  14. <type>String</type>
  15. <null_value></null_value>
  16. </attribute>
  17. </structure>
  18. </dictionary>

原始文章