Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 7c3ac8f

Browse files
Merge pull request #7 from AlexeySetevoi/develop
Add dicts feature
2 parents f1143a7 + fd15ee6 commit 7c3ac8f

File tree

5 files changed

+147
-1
lines changed

5 files changed

+147
-1
lines changed

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,39 @@ clickhouse_dbs_custom:
100100
- { name: testu4, state: present }
101101
```
102102
103+
F: You can create dictionary via odbc
104+
```
105+
clickhouse_dicts:
106+
test1:
107+
name: test_dict
108+
odbc_source:
109+
connection_string: "DSN=testdb"
110+
source_table: "dict_source"
111+
lifetime:
112+
min: 300
113+
max: 360
114+
layout: hashed
115+
structure:
116+
key: "testIntKey"
117+
attributes:
118+
- { name: testAttrName, type: UInt32, null_value: 0 }
119+
test2:
120+
name: test_dict
121+
odbc_source:
122+
connection_string: "DSN=testdb"
123+
source_table: "dict_source"
124+
lifetime:
125+
min: 300
126+
max: 360
127+
layout: complex_key_hashed
128+
structure:
129+
key:
130+
attributes:
131+
- { name: testAttrComplexName, type: String }
132+
attributes:
133+
- { name: testAttrName, type: String, null_value: "" }
134+
```
135+
103136
F: Flag for remove clickhouse from host(disabled by default)
104137
```yaml
105138
clickhouse_remove: no
@@ -135,6 +168,35 @@ Including an example of how to use your role (for instance, with variables passe
135168
quota: "default",
136169
dbs: [ testu1,testu2,testu3 ] ,
137170
comment: "classic user with multi dbs and multi-custom network allow password"}
171+
clickhouse_dicts:
172+
test1:
173+
name: test_dict
174+
odbc_source:
175+
connection_string: "DSN=testdb"
176+
source_table: "dict_source"
177+
lifetime:
178+
min: 300
179+
max: 360
180+
layout: hashed
181+
structure:
182+
key: "testIntKey"
183+
attributes:
184+
- { name: testAttrName, type: UInt32, null_value: 0 }
185+
test2:
186+
name: test_dict
187+
odbc_source:
188+
connection_string: "DSN=testdb"
189+
source_table: "dict_source"
190+
lifetime:
191+
min: 300
192+
max: 360
193+
layout: complex_key_hashed
194+
structure:
195+
key:
196+
attributes:
197+
- { name: testAttrComplexName, type: String }
198+
attributes:
199+
- { name: testAttrName, type: String, null_value: "" }
138200
clickhouse_dbs_custom:
139201
- { name: testu1 }
140202
- { name: testu2, state:present }
@@ -150,6 +212,7 @@ Tag | Action
150212
install | Only installation of packages
151213
config_sys | Only configuration system configs(users.xml and config.xml)
152214
config_db | Only add&remove databases
215+
config_sys / Only regenerate dicts
153216
config | config_sys+config_db
154217
155218
License

tasks/config_dict.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- name: Config | Generate dictionary config
2+
template:
3+
src: dicts.j2
4+
dest: "{{ clickhouse_path_configdir }}/auto_dictionary.xml"
5+
become: true

tasks/main.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
tags: [remove]
2222

2323
- include: precheck.yml
24-
tags: [precheck,config,config_sys,config_db]
24+
tags: [precheck,config,config_sys,config_db,config_dict]
2525

2626
- include: config_sys.yml
2727
when: clickhouse_rt_isinstalled.rc == 0 and clickhouse_remove|bool == False
@@ -30,3 +30,7 @@
3030
- include: config_db.yml
3131
when: clickhouse_rt_isinstalled.rc == 0 and clickhouse_remove|bool == False
3232
tags: [config,config_db]
33+
34+
- include: config_dict.yml
35+
when: clickhouse_rt_isinstalled.rc == 0 and clickhouse_remove|bool == False
36+
tags: [config,config_dict]

templates/dicts.j2

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0"?>
2+
<!-- {{ ansible_managed }} -->
3+
<dictionaries>
4+
{% for dict in clickhouse_dicts %}
5+
<dictionary>
6+
<name>{{ clickhouse_dicts[dict].name }}</name>
7+
<source>
8+
<odbc>
9+
<connection_string>{{ clickhouse_dicts[dict].odbc_source.connection_string }}</connection_string>
10+
<table>{{ clickhouse_dicts[dict].odbc_source.source_table }}</table>
11+
</odbc>
12+
</source>
13+
<lifetime>
14+
<min>{{ clickhouse_dicts[dict].lifetime.min|default(300)}}</min>
15+
<max>{{ clickhouse_dicts[dict].lifetime.max|default(600)}}</max>
16+
</lifetime>
17+
<layout>
18+
<{{ clickhouse_dicts[dict].layout|default("hashed") }}/>
19+
</layout>
20+
<structure>
21+
{% if clickhouse_dicts[dict].structure.key.attributes is defined %}
22+
<key>
23+
{% for attribute in clickhouse_dicts[dict].structure.key.attributes %}
24+
<attribute>
25+
<name>{{ attribute.name }}</name>
26+
<type>{{ attribute.type }}</type>
27+
</attribute>
28+
{% endfor %}
29+
</key>
30+
{% else %}
31+
<id>
32+
<name>{{ clickhouse_dicts[dict].structure.key }}</name>
33+
</id>
34+
{% endif %}
35+
{% for attribute in clickhouse_dicts[dict].structure.attributes %}
36+
<attribute>
37+
<name>{{ attribute.name }}</name>
38+
<type>{{ attribute.type }}</type>
39+
<null_value>{{ attribute.null_value }}</null_value>
40+
</attribute>
41+
{% endfor %}
42+
</structure>
43+
</dictionary>
44+
{% endfor %}
45+
</dictionaries>

tests/test.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,34 @@
3232
- { name: testu3 }
3333
- { name: testu4, state: absent }
3434
- { name: testu4, state: present }
35+
clickhouse_dicts:
36+
test1:
37+
name: test_dict
38+
odbc_source:
39+
connection_string: "DSN=testdb"
40+
source_table: "dict_source"
41+
lifetime:
42+
min: 300
43+
max: 360
44+
layout: hashed
45+
structure:
46+
key: "testIntKey"
47+
attributes:
48+
- { name: testAttrName, type: UInt32, null_value: 0 }
49+
test2:
50+
name: test_dict
51+
odbc_source:
52+
connection_string: "DSN=testdb"
53+
source_table: "dict_source"
54+
lifetime:
55+
min: 300
56+
max: 360
57+
layout: complex_key_hashed
58+
structure:
59+
key:
60+
attributes:
61+
- { name: testAttrComplexName, type: String }
62+
attributes:
63+
- { name: testAttrName, type: String, null_value: "" }
3564
roles:
3665
- ansible-clickhouse

0 commit comments

Comments
 (0)