ClickHouse / ClickHouse/dbt-clickhouse

feat: replace regex+macro MV external target with config.get_rendered

Open
#701 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
362
Forks
177
Avg merge
2d 10h
Merged PRs (30d)
8

Description

I have closed https://github.com/ClickHouse/dbt-clickhouse/pull/645 as it can't be developed until https://github.com/dbt-labs/dbt-core/pull/12965 is merged. Keeping this issue open to track when that PR get merged so we can definetively work on it.

# TL, DR of the PR:

Replaces the `materialization_target_table()` macro + SQL comment regex approach for external-target materialized views with `config.get_rendered('target_table')`, a clean dbt-native config key.

### Before

Users had to call a macro that injected a SQL comment, which the materialization then regex-parsed:

```sql
{{ config(materialized='materialized_view') }}
{{ materialization_target_table(ref('my_target')) }} {# outputs: -- materialization_target_table: schema.table #}
SELECT ...
```

This was incompatible with dbt-fusion (which does static DAG analysis, not SQL comment parsing) and required the regex:
```jinja
{%- set target_match = modules.re.search('--\\s*materialization_target_table:\\s*(.+?)\\s*$', sql, modules.re.MULTILINE) -%}
```

### After

```sql
{{ config(
materialized='materialized_view',
target_table=ref('my_target')
) }}
SELECT ...
```

The `target_table` value is a `RelationProxy` captured at render time via `config.get_rendered('target_table')` and used directly in the `TO` clause — no comment injection, no regex, no `| string` coercion.

Contributor guide

Open the contributing guide

Research direction

Wait for dbt-core PR #12965 to merge before starting. Then inspect the materialized_view implementation and the materialization_target_table() macro path, replacing the SQL-comment regex approach with the target_table config and config.get_rendered('target_table') flow. Done means the target is used directly in the TO clause without comment injection or regex parsing.

Written by the indexing model from the issue text.

Assessment

Tech stack
clickhouse, python, sql
Domain
data-engineering, databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.