-
Notifications
You must be signed in to change notification settings - Fork 140
Fix: persist docs for Replicated cluster setups #494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Note: for the added test to catch regressions in CI you should add the following to - name: Run HTTP tests on replicated cluster
env:
DBT_CH_TEST_CLUSTER: test_replica
DBT_CH_TEST_CLUSTER_MODE: True
run: |
PYTHONPATH="${PYTHONPATH}:dbt"
pytest tests/
# or just run the comment test:
# pytest tests/integration/adapter/clickhouse/test_clickhouse_comments.py |
7f99238
to
4841279
Compare
failure requires `test_replica` cluster to be used.
The previous version of this macro blended the `MODIFY COMMENT` command for the table comment with the `COMMENT COLUMN` commands for the column comments, inside the same `ALTER TABLE`. This combined syntax **does not work** with `ON CLUSTER`. (This was thought to be a clickhouse bug, but that bug is fixed and the behavior remains.) The revised macro now sends a separate `ALTER TABLE` for the table comment `MODIFY COMMENT`, and a separate one for all the `COMMENT COLUMN` commands. I've split it up into 2 helper macros that accomplish each task for maintainability. This also works on non-cluster setups so there is no need to further complicate it by combining table and column comment alterations into a single ALTER. `clickhouse__persist_docs` now runs the relation (table comment) helper macro if `persist_relations_docs()` is set and descriptions exist for the relation and the column comment helper macro if `persist_column_docs()` and columns are defined in the model. Additionally, the formatting was cleaned up for multiple column comments so that comments for a different column are not appearing on the same line. Just makes it easier to read in clickhouse/dbt logs. Example: It produced comments like: ```sql alter table <table> [ON CLUSTER] modify comment $dbt_comment_literal_block$<table comment> $dbt_comment_literal_block$, comment column `col1_name` $dbt_comment_literal_block$<column comment> $dbt_comment_lieteral_block$, comment column `col2_name` ... ``` A bit messy, but works on a single node. Although `ON CLUSTER` is correctly added, this syntax is incorrect and ONLY produces table and column comments for the initiator node. Now it does: ```sql alter table <table> [ON CLUSTER] modify comment $dbt_comment_literal_block$ <table comment> $dbt_comment_literal_block$ alter table <table> [ON CLUSTER] comment column `col1_name` $dbt_comment_literal_block$<column multi linecomment>$dbt_comment_literal_block$, comment column `col2_name` $dbt_comment$ <column comment>$dbt_comment$, ... ```
4841279
to
671f7d0
Compare
Tried to retrigger it for attention. Could I please get the workflows approved or a review? |
@BentsiLeviav Sorry for tagging, but any chance you're willing to approve the workflows so I can get a review on this PR? You were the only one showing any maintainer activity recently. It solves a bug that's been around for a while (and imo adds better separation of concerns to the macro). I've shown with tests why the bug was missed and how the change resolves it. Github Copilot Review
This pull request introduces significant refactoring and improvements to the way documentation comments are persisted in ClickHouse tables and columns within the dbt-clickhouse project. Here’s a concise review, highlighting the main changes, positives, and some considerations: Summary of Changes1. Refactoring
|
Summary
Fix persist docs for replicated cluster setups. (Solves #295)
Split persist docs macro into two alter statements to handle cases where on cluster wouldn't persist comments on other replicas.
Checklist
Delete items not relevant to your PR:
Note for maintainers
Note that current github integrations tests do not use the cluster
test_replica
and hence didn't see the issue. The added tests only fail & pass usingtest_replica
cluster (i.e. replicated (and sharded if needed) cluster setups).Explanation
The previous version of this macro blended the
MODIFY COMMENT
command for the table comment with theCOMMENT COLUMN
commands for the column comments, inside the sameALTER TABLE
.This combined syntax does not work with
ON CLUSTER
for replicated setups. (This was thought to be a clickhouse bug, but that bug is fixed and the behavior remains.)The revised macro now sends a separate
ALTER TABLE
for the table commentMODIFY COMMENT
, and a separate one for all theCOMMENT COLUMN
commands.I've split it up into 2 helper macros that accomplish each task for maintainability. This also works on non-cluster setups so there is no need to further complicate it by combining table and column comment alterations into a single ALTER.
clickhouse__persist_docs
now runs the relation (table comment) helper macro, ifpersist_relations_docs()
is set and descriptions exist for the relation, and runs the column comment helper macro ifpersist_column_docs()
is set and columns are defined in the model.Additionally, the formatting was cleaned up for multiple column comments so that comments for a different column are not appearing on the same line. Just makes it easier to read in clickhouse/dbt logs.
Example:
Previous macro produced comments like:
A bit messy, but works on a single node.
Although
ON CLUSTER
is correctly added, this syntax is incorrect in a replicated setup and ONLY produces table and column comments for the initiator node. Now it does:Edit: Removed dev test leftovers.
Fixes: #295