Skip to content

fix(materialized_view): persist docs before a refreshable view's initial refresh - #811

Open
gedaliakliger wants to merge 3 commits into
ClickHouse:mainfrom
gedaliakliger:fix/581-refreshable-mv-comments
Open

gedaliakliger wants to merge 3 commits into
ClickHouse:mainfrom
gedaliakliger:fix/581-refreshable-mv-comments

Conversation

@gedaliakliger

@gedaliakliger gedaliakliger commented Nov 18, 2026 •

Copy link
Copy Markdown

Summary

With catchup=False a refreshable materialized view is created without EMPTY, so ClickHouse starts its first refresh at once. A non-APPEND refresh replaces the target with a table built from the structure the target had when the refresh started, so the comments persist_docs added while it ran were lost once the refresh finished.

clickhouse__create_mvs now persists the docs on the target table before it creates the views, when the model is refreshable and the view is not created with EMPTY. This covers the first run and --full-refresh. Not covered: a plain dbt run that recreates a missing view through clickhouse__update_mv, where only comments new in that run can still be lost.

The new test uses a slow query so the refresh outlives the run; it fails on main and passes here. Run locally on a single-node ClickHouse 26.3: the materialized_view and persist_docs integration tests over HTTP and the refreshable MV tests over the native driver. Cluster, Cloud and newer server versions are left to CI.

Fixes #581

Checklist

  • Unit and integration tests covering the common scenarios were added
  • A changelog entry was added following Updating the Changelog (user-facing, concise, PR link)

Note

Low Risk
Narrows timing of existing persist_docs for one materialized-view path; low blast radius with targeted integration coverage.

Overview
Fixes lost persist_docs comments on refreshable materialized views when catchup=False. Without EMPTY, ClickHouse starts the first refresh immediately; a non-APPEND refresh rebuilds the target from the schema snapshot taken at refresh start, so docs applied at the end of dbt run were wiped once the refresh finished.

clickhouse__create_mvs now calls persist_docs on the target before creating the views when the model is refreshable and the view is not created with EMPTY (first run and --full-refresh). A changelog entry and an integration test (sleepEachRow so the refresh outlives the run) assert table and column comments in system.tables / system.columns after the refresh completes.

Reviewed by Cursor Bugbot for commit 77801e0. Bugbot is set up for automated code reviews on this repo. Configure here.

…ial refresh

With catchup=False a refreshable materialized view starts its first refresh when it is created. A non-APPEND refresh replaces the target table with one built from the structure the target had when the refresh started, so the comments persist_docs added while it ran were lost. They are now added before the views are created.

Fixes ClickHouse#581
@Flipmonster Flipmonster reopened this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

persist_docs not working for materialized views with append set to False

3 participants