How to Use Snowflake Tags
Snowflake supports tags on objects such as tables. Tags are schema-level objects you can attach to other objects. Optionally, you can specify a tag string value when assigning the tag to an object.
There are two steps to using tags within a DataOps project:
- Creating the tag, typically by SOLE (Snowflake Object Lifecycle Engine).
- Associating the tag with a Snowflake object.
- Use the SOLE configuration to apply tags to objects created by SOLE.
- Use the MATE object metadata to apply tags to tables and views created by MATE (Modelling and transformation Engine).
Creating the tag in SOLE
Tags are schema-level objects within SOLE. You can configure them under the schemas:
key in the configuration file. below is a sample configuration:
databases:
"{{ env.DATAOPS_DATABASE }}":
schemas:
SAMPLE_SCHEMA:
tags:
EXAMPLE_TAG:
grants:
APPLY:
- WRITER
This sample creates a tag called EXAMPLE_TAG
in the SAMPLE_SCHEMA
of the DataOps database. It also grants the WRITER
role the APPLY
privilege, which allows MATE to apply the tag to MATE objects.
You can apply several optional configuration parameters to tags as listed in the tags reference guide.
Applying tags to SOLE objects
Apply tags to SOLE objects using the with_tags
key in the object definition.
For example, the following configuration creates a table and assigns it the EXAMPLE_TAG
created in the above topic. If the tag is not in the same schema or database as the object, use the keys database:
and schema:
.
databases:
"{{ env.DATAOPS_DATABASE }}":
schemas:
SAMPLE_SCHEMA:
tables:
TEST_TABLE:
with_tags:
EXAMPLE_TAG:
value: Example value
Applying tags to MATE objects
Tags are applied to MATE objects using the MATE governance macros. These macros rely on a configured post-hook. If you have used other methods to apply grants, such as custom macros, be careful when enabling the governance post-hook to ensure that the grants are correct. In particular, if you have used the meta:
configuration of a MATE model, you must clear this before enabling the macros.
Once you have enabled the macros, use the meta:
section of a MATE model configuration to configure tags. For example, you can use the configuration below in a MATE schema file (a .yml file in the model directory) to associate the EXAMPLE_TAG
created in SOLE with the example_mate_model
.
version: 2
models:
- name: example_mate_model
meta:
tags:
SAMPLE_SCHEMA.EXAMPLE_TAG: Example value
The SAMPLE_SCHEMA
at the start of the tag is required to ensure that the appropriate tag is selected.