Skip to content

feat: configure distributed models with is_distributed - #777

Open
canbekley wants to merge 6 commits into
mainfrom
refactor/extract-distributed-from-materialization
Open

canbekley wants to merge 6 commits into
mainfrom
refactor/extract-distributed-from-materialization

Conversation

@canbekley

@canbekley canbekley commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

distributed_table and distributed_incremental are table and incremental with a Distributed table on top, but dbt-core does not treat them as such. dbt-core checks materialized == "incremental" in Python, which the is_incremental() macro override cannot reach:

This PR introduces a model config is_distributed as the standard way to configure distributed models:
config(materialized='incremental', is_distributed=True). Configuring them with materialized='distributed_table' or 'distributed_incremental' keeps working, but is deprecated and logs a warning.

Building on this, the microbatch strategy is now supported for distributed incremental models:
config(materialized='incremental', is_distributed=True, incremental_strategy='microbatch', ...)

Supersedes #444.

Additional notes

  • is_distributed accepts booleans and the strings 'true'/'false', and raises an error for other values. Other materializations ignore it, so it can be set for a whole folder with +is_distributed.
  • Contracted models moving to is_distributed=True must set on_schema_change to append_new_columns or fail, as for any incremental model.
  • The deprecation warning fails runs that use --warn-error until models migrate.

Out of scope

The distributed implementations are only moved into macros, apart from microbatch support. Merging them into the table and incremental materializations, as suggested in #439, may follow.

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)
  • For significant changes, documentation in docs was updated with further explanations or tutorials

Note

Medium Risk
Touches core materialization macros and adapter settings for distributed workloads; misconfiguration could break cluster builds, though mitigated by warnings and tests.

Overview
Introduces the is_distributed model flag so standard table/incremental materializations delegate to the ClickHouse distributed macros, while legacy distributed_* configs remain but emit deprecation warnings. Extends distributed incremental flows with microbatch support, shared predicate helpers, and updated clone/contract logic, plus refreshed docs, README mentions, and broad test coverage (unit + cluster integration) for the new behavior.

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

@canbekley
canbekley force-pushed the refactor/extract-distributed-from-materialization branch from cf46bfa to de18aea Compare November 4, 2026 09:27
@workflow-authentication-public workflow-authentication-public Bot added the needs-docs PR has user-visible changes without matching docs updates label Nov 4, 2026
@workflow-authentication-public

workflow-authentication-public Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Docs drift check: this PR looks like it needs doc updates.

  • docs/index.mdx: the "Supported features" checklist (#supported-features) still lists "Distributed table materialization (experimental)" and "Distributed incremental materialization (experimental)" as separate entries. Replace them with a single entry for distributed table/incremental models via is_distributed=True, matching the equivalent README.md bullet and the experimental-features table updated in this PR.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Both new changelog entries lack the required PR links, and the first needs shortening to the prescribed one or two sentences.

1 open issue
What changed in this PR

This PR introduces is_distributed=True for standard table and incremental models, allowing dbt-core to recognize distributed models for microbatch scheduling and contract validation.

Changes:

  • Routes standard materializations through shared distributed macros while retaining deprecated materialization names with warnings.
  • Adds distributed microbatch support and centralizes distributed-model detection.
  • Updates documentation and tests for the new configuration and backward compatibility.
File Description
tests/​unit/​test_is_distributed.py Tests flag parsing, legacy names, and invalid values.
tests/​integration/​adapter/​incremental/​test_incremental_microbatch.py Adds distributed microbatch coverage.
tests/​integration/​adapter/​incremental/​test_distributed_incremental.py Migrates incremental fixtures to the flag.
tests/​integration/​adapter/​grants/​test_distributed_grants.py Updates distributed grants configuration and assertions.
tests/​integration/​adapter/​constraints/​fixtures_constraints.py Migrates contract fixtures with schema-change settings.
tests/​integration/​adapter/​clickhouse/​test_clickhouse_table_ttl.py Uses the flag for distributed TTL coverage.
tests/​integration/​adapter/​clickhouse/​test_clickhouse_table_materializations.py Tests legacy warnings and project-level configuration.
tests/​integration/​adapter/​aliases/​test_aliases.py Migrates distributed alias fixtures.
docs/​materializations.mdx Documents distributed configuration and microbatch support.
docs/​index.mdx Updates the distributed feature listing.
docs/​dbt-core-v2-fusion-and-platform.mdx Updates distributed configuration terminology.
dbt/​include/​clickhouse/​macros/​materializations/​table.sql Routes flagged tables to distributed logic.
dbt/​include/​clickhouse/​macros/​materializations/​incremental/​incremental.sql Adds distributed routing and shared microbatch logic.
dbt/​include/​clickhouse/​macros/​materializations/​incremental/​distributed_incremental.sql Extracts distributed logic and adds microbatch handling.
dbt/​include/​clickhouse/​macros/​materializations/​distributed_table.sql Extracts distributed logic and adds deprecation warnings.
dbt/​include/​clickhouse/​macros/​materializations/​clone.sql Uses centralized detection for clone eligibility.
dbt/​adapters/​clickhouse/​impl.py Adds distributed detection and adapts model settings.
CHANGELOG.md Records the configuration migration and microbatch support.

Review effort: Balanced

Comment thread CHANGELOG.md Resolved
canbekley added a commit that referenced this pull request Nov 4, 2026
@canbekley
canbekley force-pushed the refactor/extract-distributed-from-materialization branch from de18aea to bc78d16 Compare November 4, 2026 12:14
canbekley added a commit that referenced this pull request Nov 4, 2026
@canbekley
canbekley force-pushed the refactor/extract-distributed-from-materialization branch from bc78d16 to 73a0a79 Compare November 4, 2026 12:22
@canbekley canbekley changed the title refactor: extract "distributed_" from materialized configuration into flag feat: configure distributed models with is_distributed Nov 4, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0036c0f. Configure here.

{% elif incremental_strategy == 'delete_insert' %}
{% do clickhouse__incremental_delete_insert(existing_relation, unique_key, incremental_predicates, True) %}
{% elif incremental_strategy == 'microbatch' %}
{% do clickhouse__incremental_microbatch(existing_relation, unique_key, incremental_predicates, True) %}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deprecated microbatch path skips batching

Medium Severity

The new microbatch branch lives in the shared clickhouse__distributed_incremental macro, which the deprecated materialized='distributed_incremental' wrapper also calls. dbt-core only selects MicrobatchModelRunner when materialized == 'incremental', so that path never sets __dbt_internal_microbatch_event_time_start/end and never event-time-filters refs. The run still takes the microbatch branch and performs a single unwindowed delete+insert over the full compiled SQL, so models that keep the old materialization name can skip batch windows and delete/insert the wrong rows.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0036c0f. Configure here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. will fix this by throwing an exception when the deprecated materialized='distributed_incremental' configuration is used together with incremental_strategy='microbatch'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-docs PR has user-visible changes without matching docs updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants