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: 

Apply unitycatalog tags programmatically

afisl
New Contributor II

Hello,

I'm interested in the "Tags" feature of columns/schemas/tables of the UnityCatalog (described here: https://learn.microsoft.com/en-us/azure/databricks/data-governance/unity-catalog/tags)

I've been able to play with them by hand and would now like to integrate them from a programmatic perspective. I was able to QUERY them programmatically (described here https://learn.microsoft.com/en-us/azure/databricks/sql/language-manual/information-schema/column_tag... but not SET/UPDATE them programmatically.

I think it should be possible to set them programmatically according to the following paragraph in the documentation:

Currently, Azure Databricks supports tagging SQL commands with catalogs, schemas, tables (views, materialized views, streaming tables), and table columns. Learn more about the Databricks SQL tag commands at SQL language reference.

Source: https://learn.microsoft.com/en-us/azure/databricks/data-governance/unity-catalog/tags#manage-tags-wi...

I've tried UPDATE statement on the information_schema.column_tags table, but get an spark error message:

SparkUnsupportedOperationException: UPDATE TABLE is not supported temporarily.

Any idea how I can set tags programmatically?

Thanks for your support,

Best

Antoine

1 ACCEPTED SOLUTION

Accepted Solutions

melbourne
Contributor

Hi @afisl 

Use following SQL command to add tags programmatically:

alter table <table_name>          
set tags ('key1' = 'value1', 'key2' = 'value2')

View solution in original post

8 REPLIES 8

afisl
New Contributor II

Hi @Retired_mod ,

thanks for your answer. The documentation you quoted is exactly the one I saw.

But this paragraph is for me unclear:"

Manage Tags with SQL Commands:

  • This feature is available for Databricks Runtime versions 13.3 and above.
  • You can use Databricks SQL commands to tag catalogs, schemas, tables (views, materialized views, streaming tables), and table columns.
  • Learn more about the Databricks SQL tag commands in the SQL language reference."

I cannot find the Databricks SQL tag commands in the SQL language reference. Could you help me there please?

Thanks,

Antoine

melbourne
Contributor

Hi @afisl 

Use following SQL command to add tags programmatically:

alter table <table_name>          
set tags ('key1' = 'value1', 'key2' = 'value2')

is there a way to apply column tags programmatically to views?

Marleen
New Contributor II
alter table <table_name> alter column <column_name>         
set tags ('key1' = 'value1', 'key2' = 'value2')

cltj
New Contributor III

Hi lets explore how  AI in a comminication channel like this will expoenentially waste the time users use to craft their post and explain their issue or question.  

I do not understand why a simple "I dont know, but I will find out" is out of range these days.

Sometimes we can make just as much or even more impact with simplicity without sending users in a loop or down the wrong rabbit hole, perfectly illustrated here by melbourne.

databass
New Contributor II

just confirming, that as at March 2024 you can use SQL to set/unset tags on:

  1. Tables
  2. Table Columns
  3. Views

But NOT on View Columns

however you CAN do this via the UI. 

Mamzy10
New Contributor II

@afisl did you ever get down to the bottom of this? im trying to automatically set PI tags against column with certain words

Jiri_Koutny
New Contributor III

Hi, running ALTER TABLE SET TAGS works on views too!

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now