From a2ec910097786d78fc432c88b0d3192effcf20ba Mon Sep 17 00:00:00 2001 From: HarshCasper Date: Fri, 1 Nov 2024 16:33:50 +0530 Subject: [PATCH] add docs on tags --- content/en/user-guide/streams/index.md | 2 +- content/en/user-guide/tags/index.md | 119 +++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 content/en/user-guide/tags/index.md diff --git a/content/en/user-guide/streams/index.md b/content/en/user-guide/streams/index.md index b4171f8..7e8bff7 100644 --- a/content/en/user-guide/streams/index.md +++ b/content/en/user-guide/streams/index.md @@ -13,7 +13,7 @@ The Snowflake emulator supports managed streams. You can create a stream locally ## Getting started -This guide is designed for users new to Streams and assumes basic knowledge of SQL and Snowflake. Start your Snowflake emulator and connect to it using an SQL client to execute the queries below.. +This guide is designed for users new to Streams and assumes basic knowledge of SQL and Snowflake. Start your Snowflake emulator and connect to it using an SQL client to execute the queries below. The following sections guide you through a simple example of using Streams to track changes in a table that stores information about gym members. We will create tables to store member information and their signup dates, and then use a stream to capture changes made to the members' table. diff --git a/content/en/user-guide/tags/index.md b/content/en/user-guide/tags/index.md new file mode 100644 index 0000000..f8cc9db --- /dev/null +++ b/content/en/user-guide/tags/index.md @@ -0,0 +1,119 @@ +--- +title: "Tags" +linkTitle: "Tags" +weight: 15 +description: Get started with Tags in LocalStack for Snowflake +--- + +## Introduction + +Snowflake tags allow you to categorize and manage Snowflake objects by associating custom metadata with them. These tags support governance, cost tracking, and data lineage by enabling organizations to label resources with business-relevant information. + +The Snowflake emulator supports tags, allowing you to apply these tags to the local Snowflake tables, views, and databases using the same commands and syntax as the Snowflake service. The following operations are supported: + +- [CREATE TAG](https://docs.snowflake.com/en/sql-reference/sql/create-tag) +- [SHOW TAGS](https://docs.snowflake.com/en/sql-reference/sql/show-tags) +- [ALTER TAG](https://docs.snowflake.com/en/sql-reference/sql/alter-tag) +- [DROP TAG](https://docs.snowflake.com/en/sql-reference/sql/drop-tag) + +## Getting started + +This guide is designed for users new to tagging in Snowflake and assumes basic knowledge of SQL and Snowflake. Start your Snowflake emulator and connect to it using an SQL client to execute the queries below. + +The following sections guide you through an example of creating a database, adding a tag, and using the tag to track metadata in Snowflake. + +### Create a Database + +The following SQL snippet demonstrates how to create a database named `tag_test_db`. + +```sql +CREATE DATABASE IF NOT EXISTS tag_test_db; +``` + +The expected output is: + +```sql ++--------------------------------------------+ +| status | +|--------------------------------------------| +| Database TAG_TEST_DB successfully created. | ++--------------------------------------------+ +0 Row(s) produced. Time Elapsed: 0.163s +``` + +### Create a Tag + +To create a tag, use the `CREATE TAG` statement. The following example demonstrates how to create a tag named `tag1`. + +```sql +CREATE TAG tag1; +``` + +The expected output is: + +```sql ++--------------------------------+ +| ?COLUMN? | +|--------------------------------| +| Tag TAG1 successfully created. | ++--------------------------------+ +0 Row(s) produced. Time Elapsed: 0.057s +``` + +### Assign Tag to Database + +To assign a tag to a database, use the `ALTER DATABASE` statement. The following example demonstrates how to assign the tag `tag1` with the value `'test 123'` to the `tag_test_db` database. + +```sql +ALTER DATABASE tag_test_db SET TAG tag1 = 'test 123'; +``` + +The expected output is: + +```sql ++----------------------------------+ +| ?column? | +|----------------------------------| +| Statement executed successfully. | ++----------------------------------+ +0 Row(s) produced. Time Elapsed: 0.026s +``` + +### Query Tag Value + +To retrieve the value of a tag assigned to a database, use the `SELECT SYSTEM$GET_TAG` statement. The following example demonstrates how to query the value of `tag1` assigned to the `tag_test_db` database. + +```sql +SELECT SYSTEM$GET_TAG('tag1', 'tag_test_db', 'database'); +``` + +The expected output is: + +```sql ++----------------+ +| SYSTEM$GET_TAG | +|----------------| +| test 123 | ++----------------+ +1 Row(s) produced. Time Elapsed: 0.565s +``` + +### Query Tag References + +To view all references of a tag within a database, use the `INFORMATION_SCHEMA.TAG_REFERENCES` function. The following example demonstrates how to query the `tag_test_db` database for references to the `tag1` tag. + +```sql +SELECT * +FROM TABLE(tag_test_db.INFORMATION_SCHEMA.TAG_REFERENCES('tag_test_db', 'database')); +``` + +The expected output is: + +```sql ++--------------+------------+----------+-----------+----------+-----------------+---------------+-------------+----------+-------------+ +| TAG_DATABASE | TAG_SCHEMA | TAG_NAME | TAG_VALUE | LEVEL | OBJECT_DATABASE | OBJECT_SCHEMA | OBJECT_NAME | DOMAIN | COLUMN_NAME | +|--------------+------------+----------+-----------+----------+-----------------+---------------+-------------+----------+-------------| +| TAG_TEST_DB | PUBLIC | TAG1 | test 123 | DATABASE | NULL | NULL | TAG_TEST_DB | DATABASE | NULL | ++--------------+------------+----------+-----------+----------+-----------------+---------------+-------------+----------+-------------+ +1 Row(s) produced. Time Elapsed: 0.528s +```