Skip to content

Commit 0abe257

Browse files
committed
Add failing replicated persist docs test
failure requires `test_replica` cluster to be used.
1 parent d9665af commit 0abe257

File tree

1 file changed

+120
-1
lines changed

1 file changed

+120
-1
lines changed

tests/integration/adapter/clickhouse/test_clickhouse_comments.py

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@
1818
1919
"""
2020

21+
ref_models__replicated_table_comment_sql = """
22+
{{
23+
config(
24+
materialized = "table",
25+
persist_docs = {"relation": true, "columns": true},
26+
engine="ReplicatedMergeTree('/clickhouse/tables/{uuid}/one-shard', '{replica}' )"
27+
)
28+
}}
29+
30+
select
31+
'foo' as first_name,
32+
'bar' as second_name
33+
34+
"""
35+
2136
ref_models__view_comment_sql = """
2237
{{
2338
config(
@@ -43,6 +58,13 @@
4358
description: "XXX first description"
4459
- name: second_name
4560
description: "XXX second description"
61+
- name: replicated_table_comment
62+
description: "YYY table"
63+
columns:
64+
- name: first_name
65+
description: "XXX first description"
66+
- name: second_name
67+
description: "XXX second description"
4668
- name: view_comment
4769
description: "YYY view"
4870
columns:
@@ -59,12 +81,13 @@ def models(self):
5981
return {
6082
"schema.yml": ref_models__schema_yml,
6183
"table_comment.sql": ref_models__table_comment_sql,
84+
"replicated_table_comment.sql": ref_models__replicated_table_comment_sql,
6285
"view_comment.sql": ref_models__view_comment_sql,
6386
}
6487

6588
@pytest.mark.parametrize(
6689
'model_name',
67-
['table_comment', 'view_comment'],
90+
["table_comment", "replicated_table_comment", "view_comment"],
6891
)
6992
def test_comment(self, project, model_name):
7093
if os.environ.get('DBT_CH_TEST_CLOUD', '').lower() in ('1', 'true', 'yes'):
@@ -81,3 +104,99 @@ def test_comment(self, project, model_name):
81104
assert column_comment.startswith("XXX")
82105

83106
assert column_node['metadata']['comment'].startswith("YYY")
107+
108+
# Ensure comment is propoagated to all replicas on cluster
109+
#cluster = project.test_config['cluster']
110+
111+
# local_relation = relation_from_name(project.adapter, model_name)
112+
# if cluster:
113+
# ensure_column_comments_consistent_across_replicas(project, cluster, local_relation)
114+
# ensure_table_comment_on_cluster(project, cluster, local_relation)
115+
116+
117+
118+
# def ensure_table_comment_on_cluster(project, cluster, local_relation):
119+
# """Ensure all replicas have same comment for given relation"""
120+
# # Returns 'ok' if exactly one distinct comment exists across all replicas for this table; otherwise 'mismatch'.
121+
# sql = f"""
122+
# SELECT
123+
# if(COUNT(DISTINCT comment) = 1, 'ok', 'mismatch') AS status
124+
# FROM clusterAllReplicas('{cluster}', system.tables)
125+
# WHERE database = currentDatabase()
126+
# AND name = '{local_relation.identifier}'
127+
# """
128+
# result = project.run_sql(sql, fetch="one")
129+
# assert result[0] == "ok"
130+
131+
# sql = f"""
132+
# SELECT
133+
# hostname(),
134+
# comment
135+
# FROM clusterAllReplicas('{cluster}', system.tables)
136+
# WHERE `table` = '{local_relation.identifier}'
137+
# """
138+
139+
# result = project.run_sql(sql, fetch="all")
140+
141+
# for _table_row in result:
142+
# assert _table_row[-1].startswith("YYY")
143+
144+
# def ensure_column_comments_consistent_across_replicas(project, cluster, local_relation):
145+
# # This query groups by column name and checks that each has exactly one distinct comment across replicas.
146+
# check_sql = f"""
147+
# SELECT
148+
# name AS column_name,
149+
# COUNT(DISTINCT comment) AS distinct_comment_count,
150+
# groupArray((hostName(), comment)) AS per_replica_comments
151+
# FROM clusterAllReplicas('{cluster}', system.columns)
152+
# WHERE database = currentDatabase()
153+
# AND table = '{local_relation.identifier}'
154+
# GROUP BY column_name
155+
# """
156+
# rows = project.run_sql(check_sql, fetch="all")
157+
158+
# mismatches = [r for r in rows if r[1] != 1]
159+
# if mismatches:
160+
# print("Column comment mismatches:", mismatches)
161+
162+
# assert not mismatches
163+
164+
# sql = f"""
165+
# SELECT
166+
# name,
167+
# groupArray(hostname()) as hosts,
168+
# groupUniqArray(comment) as comments,
169+
# length(comments) as num_comments
170+
# FROM clusterAllReplicas('{cluster}', system.columns)
171+
# WHERE table = '{local_relation.identifier}'
172+
# GROUP BY name
173+
# """
174+
175+
# result = project.run_sql(sql, fetch="all")
176+
177+
# print("WOW"*100)
178+
# print("\n\n")
179+
# print(result)
180+
# print("WOW"*100)
181+
182+
# for _col in result:
183+
# assert _col[-1] == 1
184+
185+
# assert result == []
186+
187+
188+
# sql = f"""
189+
# SELECT
190+
# name,
191+
# count(hostname())
192+
# FROM clusterAllReplicas('{cluster}', system.columns)
193+
# WHERE table = '{local_relation.identifier}'
194+
# GROUP BY name
195+
# """
196+
# result = project.run_sql(sql, fetch="all")
197+
# assert result[-1] == NUM_CLUSTER_NODES
198+
199+
# assert result == []
200+
201+
202+

0 commit comments

Comments
 (0)