Skip to content

feat(core): support refreshable materialized views (NUM-6762)#110

Merged
alvarogar4 merged 2 commits intomainfrom
alvaro/num-6762-obsession-implement-refreshable-views
Apr 20, 2026
Merged

feat(core): support refreshable materialized views (NUM-6762)#110
alvarogar4 merged 2 commits intomainfrom
alvaro/num-6762-obsession-implement-refreshable-views

Conversation

@alvarogar4
Copy link
Copy Markdown
Member

Summary

  • Adds an optional refresh field to materializedView() covering all ClickHouse refreshable-MV clauses (EVERY/AFTER, OFFSET, RANDOMIZE FOR, DEPENDS ON, SETTINGS, APPEND, EMPTY). GA since ClickHouse 24.10.
  • Planner emits ALTER TABLE … MODIFY REFRESH … for schedule-only changes and drop+recreate for structural ones. APPEND is structural — the server rejects toggling it via ALTER, and MODIFY REFRESH always re-emits APPEND when set (verified live; undocumented).
  • Validator rejects combinations the server refuses: missing/both every/after, malformed intervals, DEPENDS ON with REFRESH AFTER, and non-APPEND RMVs targeting replicated (SharedMergeTree / Replicated*) tables in the same schema.
  • @chkit/plugin-pull parses the REFRESH block from system.tables.create_table_query, strips Cloud-injected DEFINER / SQL SECURITY noise, and round-trips refresh: { … } into generated schema files.
  • Docs: new schema/refreshable-views.md reference page; schema/dsl-reference.md updated with the refresh row.
  • Drive-by: converts sql-validation.e2e.test.ts from test('setup'/'teardown') to beforeAll/afterAll so tests nested under the top-level describe see an initialized client (pre-existing ordering bug — same fix as the dangling fc4d2c6 commit).

Test plan

  • bun verify (typecheck + lint + test + build via Doppler CI config — customer-chx) — 33/33 tasks, 419 tests pass, 0 fail
  • Unit tests: +17 in @chkit/core (SQL rendering, diff rules, canonical, validation) and +7 in @chkit/plugin-pull (parser, DEFINER stripping, render)
  • E2E against customer-benchmark: +10 EXPLAIN AST cases for CREATE and MODIFY REFRESH, live pull round-trip, and a full CLI lifecycle test (create APPEND RMV → modify schedule via MODIFY REFRESH → drop+recreate on query change → remove)
  • Manual walkthrough against customer-benchmark exercising the full chkit generate + migrate --apply flow for create/modify/drop

Note on refresh execution: scheduled refreshes do not fire on customer-benchmark because of a cluster-side permission issue (permission denied for table refresh_coordination in system.view_refreshes.exception). chkit's DDL management is unaffected; worth filing a separate Numia infra ticket for the cluster.

Closes NUM-6762.

🤖 Generated with Claude Code

Add an optional `refresh` field to `materializedView()` covering all clauses
ClickHouse supports for refreshable MVs (GA since 24.10): EVERY/AFTER,
OFFSET, RANDOMIZE FOR, DEPENDS ON, SETTINGS, APPEND, and EMPTY.

The planner emits `ALTER TABLE ... MODIFY REFRESH ...` for schedule-only
changes and drop+recreate for structural ones. APPEND is treated as
structural because ClickHouse rejects toggling it via ALTER, and MODIFY
REFRESH always re-emits APPEND when present (the server rejects omitting
it on an existing APPEND MV).

Validator rejects combinations verified invalid against ClickHouse 25.12:
missing or both `every`/`after`, malformed intervals, `DEPENDS ON` paired
with `REFRESH AFTER`, and non-APPEND RMVs targeting `SharedMergeTree` /
`Replicated*` tables in the same schema.

`@chkit/plugin-pull` parses the REFRESH block out of
`system.tables.create_table_query`, strips Cloud-injected `DEFINER` / `SQL
SECURITY` clauses, and renders `refresh: { ... }` back into the generated
schema file.

Also converts `sql-validation.e2e.test.ts` from `test('setup'/'teardown')`
to `beforeAll/afterAll` so tests nested under the top-level `describe`
see an initialized client — pre-existing test-ordering bug.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@alvarogar4 alvarogar4 force-pushed the alvaro/num-6762-obsession-implement-refreshable-views branch from f72e0b0 to d0bf7fe Compare April 20, 2026 11:41
Prevents ticket exports, research drafts, and other working notes from
ever being tracked. Flagged in code review — Linear URLs, personal
emails, and customer hostnames sometimes end up in these files.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@alvarogar4 alvarogar4 merged commit a77c5b2 into main Apr 20, 2026
2 checks passed
@alvarogar4 alvarogar4 deleted the alvaro/num-6762-obsession-implement-refreshable-views branch April 20, 2026 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant