Skip to main content

Materialized View

  • MV, materialzed view

Overview

In Databricks, Materialized views cache the results and update them as the underlying source tables change—either on a schedule or automatically.

Installation

  • Copy the Package ID  @coalesce/databricks/materialized-view
  • In Coalesce, open the Workspace where you wish to install the package.
  • Go to the Build Setting of the Workspace, tab Packages, and click the Install button on the top right of the page.
  • Paste the Package ID, and proceed with the installation process.

Description

Databricks Materialized View

The Databricks Materialized View UDN is a versatile node that allows you to develop and deploy a Materialized View in Databricks.

A materialized view is a view where precomputed results are available for query and can be updated to reflect changes in the input. Each time a materialized view is refreshed, query results are recalculated to reflect changes in upstream datasets. All materialized views are backed by a DLT pipeline. You can refresh materialized views manually or on a schedule.

Node Configuration

The Databricks Materialized View Stage has Four configuration groups:

Node Properties

There are four configs within the Node Properties group.

PropertyDescription
Storage LocationStorage Location where the Materialized View will be created
Node TypeName of template used to create node objects
Deploy EnabledIf TRUE the node will be deployed / redeployed when changes are detected
If FALSE the node will not be deployed or will be dropped during redeployment

Key point

  • Materialized View automatically infers the structure of the source table and defines the data type of columns.Hence we create materialized view without column definition in Infer stage(keeping infer toggle enabled)
  • Re-Sync the columns and the mapping grid will be updated with the expected column structure
  • Keep the infer toggle off,create the Materializsed View with the intended column or table-level constraints

General Options

OptionDescription
Infer MV structureTrue / False toggle
- True: Materialized View Options will be disabled
- False: Materialized View Options will be visible
Schedule refreshTrue / False toggle
- True: Schedule Option will be visible
- False: Schedule Option will be disabled

Materialized View Options

Materialized View Options is available only when Infer MV Structure toggle is False.

OptionDescription
Table properties
Partition byTrue / False Toggle
- True: Enables the Column Dropdown and Textbox to add columns for partitioning
- False: Disables the Dropdown and Textbox to add columns
Table ConstraintsTrue / False Toggle
- True: Primary key and Foreign Key toggle will visible
- False : Primary key and Foreign Key toggle will Disable
Primary keyVisible when Table Constraints is True
options for Primary Key
- Primary key Name : Primary Key name is added in short
- Primary key columns : Column Dropdown and Textbox to add columns box appear to select primary key
Foreign KeyVisible when Table Constraints is True
options for Foreign Key
- Foreign key attributes : Text box appear where we can add Foreign Key Name,Parent table name,Foreign key columns
Other constraintsTrue / False Toggle
Constraints : Text box appear where we can add constraints on selected column
Options
-ColumnName : From column dropdown we can add columns
-Expected Expression : can give specific Expression
-ON VIOLATION : Two options can be selected from dropdown - Fail Update, Drop Row

Schedule Options

Schedule Options is available only when Schedule Refresh toggle is True

OptionDescription
Task ScheduleOptions in Task Schedule
- Periodic Schedule
- CRON
Schedule refesh-time periodAvailable when Task Schedule is Set to Periodic Schedule
Options in Schedule refesh-time period
-Every Hours
-Every Days
-Every Weeks
Specific interval of periodic refresh(integer value)Available when Task Schedule is Set to Periodic Schedule
CRON stringAvailable when Task Schedule is Set to CRON
CRON TIME ZONEAvailable when Task Schedule is Set to CRON

Deployment

Initial Deployment

When deployed for the first time into an environment Materialized View will execute three stages:

StageDescription
Create Materialized ViewThis stage will execute a CREATE OR REPLACE statement and create a Materialized View in the target environment

Redeployment

After the Materialized View has deployed for the first time into a target environment, subsequent deployments may result in either altering the Materialized View or recreating the Materialized View.

If a Materialized View is to be altered this will run the following stage:

Recreating the Materialized View

If anything changes other than the configuration options specified above then the Materialized View will be recreated by running a CREATE OR REPLACE statement.

Undeployment

If a Materialized View is deleted from a Workspace, that Workspace is committed to Git and that commit deployed to a higher-level environment then the Materialized View in the target environment will be dropped.

This is executed as a single stage:

StageDescription
Drop Materialized ViewRemoves the materialized view

Code

Versions

Available versions of the package.

Version #Release DateNotes
1.0.0June 06, 2025
 Initial version of Databricks Materialized View