cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

alter DLT Materialized View alter column set MASK

kranthi2
New Contributor III

I am trying to mask a column on a DLT materialized view - this is created using DLT syntax. I am not able set the column masking after creation. Appreciate any workaround.

alter DLT Materialized View alter column set MASK

1 ACCEPTED SOLUTION

Accepted Solutions

lucasrocha
Databricks Employee
Databricks Employee

Hello @kranthi2 , I hope you're doing well.

It seems that this command won't work for MVs, as it expected table. When trying to run the following command, for example:

ALTER TABLE `catalog`.`schema`.`MV` ALTER COLUMN column_ SET MASK mask_func;
We get the following error:
[EXPECT_TABLE_NOT_VIEW.NO_ALTERNATIVE] 'ALTER TABLE ... ALTER COLUMN' expects a table but `catalog`.`schema`.`MV` is a view. SQLSTATE: 42809
 
Also, if you go to the table through Catalog, and follow the docs steps:
lucasrocha_0-1725661412591.png

Doc.: https://docs.databricks.com/en/tables/row-and-column-filters.html#apply-a-column-mask

In a MV, you will face the following message:
To add or remove column mask for Materialized Views, use the CREATE OR REPLACE statement

Which indicates that, for now, this operation is not possible for MVs.

If you believe this feature of adding column mask to MVs through ALTER TABLE/VIEW would be beneficial, you could submit an idea in Databricks' Ideas Portal.

Best regards,
Lucas Rocha
Technical Solutions Engineer

View solution in original post

2 REPLIES 2

lucasrocha
Databricks Employee
Databricks Employee

Hello @kranthi2 , I hope you're doing well.

It seems that this command won't work for MVs, as it expected table. When trying to run the following command, for example:

ALTER TABLE `catalog`.`schema`.`MV` ALTER COLUMN column_ SET MASK mask_func;
We get the following error:
[EXPECT_TABLE_NOT_VIEW.NO_ALTERNATIVE] 'ALTER TABLE ... ALTER COLUMN' expects a table but `catalog`.`schema`.`MV` is a view. SQLSTATE: 42809
 
Also, if you go to the table through Catalog, and follow the docs steps:
lucasrocha_0-1725661412591.png

Doc.: https://docs.databricks.com/en/tables/row-and-column-filters.html#apply-a-column-mask

In a MV, you will face the following message:
To add or remove column mask for Materialized Views, use the CREATE OR REPLACE statement

Which indicates that, for now, this operation is not possible for MVs.

If you believe this feature of adding column mask to MVs through ALTER TABLE/VIEW would be beneficial, you could submit an idea in Databricks' Ideas Portal.

Best regards,
Lucas Rocha
Technical Solutions Engineer

kranthi2
New Contributor III

Thank you. I will submit the idea.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group