Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:MaterializeInc Materialize Dbt Materialize Commands

From Leeroopedia
Revision as of 15:38, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/MaterializeInc_Materialize_Dbt_Materialize_Commands.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources misc/dbt-materialize/dbt/adapters/materialize/connections.py
Domains Framework-Mediated Database Operations, CLI Command Translation, Transaction Management
Last Updated 2026-02-08

Overview

Wrapper documentation for dbt CLI commands when used with the Materialize adapter, covering dbt run, dbt test, dbt docs generate, and dbt run-operation with Materialize-specific transaction handling where all transaction lifecycle methods are no-ops due to autocommit mode.

Description

When dbt is used with the dbt-materialize adapter, all standard dbt CLI commands function with one critical behavioral difference: transactions are disabled. The MaterializeConnectionManager overrides five transaction lifecycle methods inherited from PostgresConnectionManager, making them all no-ops:

def add_begin_query(self, *args, **kwargs):
    pass

def add_commit_query(self, *args, **kwargs):
    pass

def begin(self):
    pass

def commit(self):
    pass

def clear_transaction(self):
    pass

This is necessary because Materialize does not support arbitrary queries within transactions, and many of dbt's internal macros produce invalid transaction blocks when run against Materialize. Combined with the autocommit mode set in open(), this means every SQL statement is implicitly committed immediately.

Key dbt commands and their Materialize behavior:

  • dbt run: Compiles and executes all models in dependency order. Each model's DDL (CREATE MATERIALIZED VIEW, CREATE VIEW, CREATE SOURCE, CREATE SINK, etc.) is executed as an individual autocommitted statement. The --vars "deploy: True" flag routes models to deployment clusters/schemas.
  • dbt test: Executes data quality tests (schema tests, custom tests). Each test query runs independently without transaction wrapping.
  • dbt docs generate: Generates catalog metadata by introspecting the Materialize catalog. Uses mz_catalog_server cluster for catalog queries (via auto_route_catalog_queries session parameter).
  • dbt run-operation: Invokes custom macros such as deploy_init, deploy_promote, deploy_await, and deploy_cleanup. These macros may use explicit BEGIN/COMMIT blocks for operations that require atomicity (such as ALTER SCHEMA SWAP).

Usage

Use this wrapper documentation when:

  • Running dbt commands against a Materialize target and needing to understand transaction behavior.
  • Debugging unexpected behavior related to transaction isolation or statement ordering.
  • Understanding why certain dbt patterns that rely on transactions (e.g., incremental model updates with rollback) behave differently on Materialize.
  • Configuring CI/CD pipelines that invoke dbt commands for Materialize deployments.

Code Reference

Source Location

File Lines Description
misc/dbt-materialize/dbt/adapters/materialize/connections.py L167-180 Transaction no-op methods: add_begin_query, add_commit_query, begin, commit, clear_transaction
misc/dbt-materialize/dbt/adapters/materialize/connections.py L112-131 open() method setting autocommit mode
misc/dbt-materialize/dbt/adapters/materialize/connections.py L133-157 cancel() method using connection close instead of pg_terminate_backend

Signature

class MaterializeConnectionManager(PostgresConnectionManager):
    TYPE = "materialize"

    # Transaction lifecycle — all no-ops
    def add_begin_query(self, *args, **kwargs): pass
    def add_commit_query(self, *args, **kwargs): pass
    def begin(self): pass
    def commit(self): pass
    def clear_transaction(self): pass

Import

from dbt.adapters.materialize.connections import MaterializeConnectionManager

I/O Contract

Inputs

Command Key Arguments Description
dbt run --vars "deploy: True", --exclude, --select Compiles and runs all selected models. With deploy: True, routes to deployment clusters/schemas.
dbt test --select, --exclude Runs data quality tests on materialized models.
dbt docs generate (none specific) Generates catalog documentation by querying Materialize system tables.
dbt run-operation macro_name, --args, --vars Invokes a named macro with optional arguments.

Outputs

Command Output Description
dbt run Run results Success/failure status for each model materialization, with timing.
dbt test Test results Pass/fail/warn/error for each test.
dbt docs generate target/catalog.json JSON catalog of all models, sources, and their columns.
dbt run-operation Macro output Logged output from the executed macro.

Usage Examples

# Standard model execution
dbt run --target prod

# Deploy models to blue-green deployment environment
dbt run --vars 'deploy: True'

# Run tests against materialized models
dbt test --target prod

# Generate documentation
dbt docs generate --target prod

# Run deployment operations
dbt run-operation deploy_init --vars '{deployment: {default: {clusters: [quickstart], schemas: [public]}}}'
dbt run-operation deploy_promote --args '{dry_run: true}'
dbt run-operation deploy_cleanup
# profiles.yml for Materialize target
my_project:
  target: prod
  outputs:
    prod:
      type: materialize
      host: my-materialize-host.example.com
      port: 6875
      user: materialize
      pass: "{{ env_var('MZ_PASSWORD') }}"
      database: materialize
      schema: public
      cluster: quickstart
      threads: 4

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment