Data classification and tagging in Snowflake - Time & Space Complexity
When we classify and tag data in Snowflake, we want to know how the time it takes changes as we add more data.
We ask: How does the work grow when the amount of data grows?
Analyze the time complexity of the following operation sequence.
-- Create a tag
CREATE TAG IF NOT EXISTS sensitive_data;
-- Apply tag to multiple tables
DECLARE tables CURSOR FOR SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema = 'SALES';
DECLARE table_name STRING;
BEGIN
OPEN tables;
LOOP
FETCH tables INTO table_name;
IF (SQLCODE != 0) THEN
LEAVE;
END IF;
EXECUTE IMMEDIATE 'ALTER TABLE IDENTIFIER(?, ?) SET TAG sensitive_data = ''true''' USING 'SALES', table_name;
END LOOP;
CLOSE tables;
END;
This sequence creates a tag and applies it to every table in a schema.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Applying the tag to each table with ALTER TABLE SET TAG.
- How many times: Once for each table in the schema.
As the number of tables grows, the number of tag applications grows the same way.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 ALTER TABLE SET TAG calls |
| 100 | 100 ALTER TABLE SET TAG calls |
| 1000 | 1000 ALTER TABLE SET TAG calls |
Pattern observation: The number of operations grows directly with the number of tables.
Time Complexity: O(n)
This means the time to tag all tables grows in a straight line as the number of tables increases.
[X] Wrong: "Applying a tag to many tables happens all at once, so time stays the same no matter how many tables."
[OK] Correct: Each table needs its own tag operation, so more tables mean more work and more time.
Understanding how tagging scales helps you plan and explain data governance tasks clearly in real projects.
"What if we tagged columns instead of tables? How would the time complexity change?"
Practice
Solution
Step 1: Understand data classification and tagging
Data classification and tagging help label data to organize and protect it.Step 2: Identify the purpose in Snowflake context
Tags are used to mark data for governance and security, not for performance or deletion.Final Answer:
To organize and protect data by labeling it with tags -> Option DQuick Check:
Data classification = Organize and protect data [OK]
- Confusing tagging with indexing for performance
- Thinking tags delete data automatically
- Assuming tags change data format
Solution
Step 1: Recall Snowflake tag creation syntax
The correct syntax uses CREATE TAG followed by the tag name and COMMENT clause.Step 2: Compare options with syntax
Only CREATE TAG tag_name COMMENT = 'description'; matches the correct syntax: CREATE TAG tag_name COMMENT = 'description';Final Answer:
CREATE TAG tag_name COMMENT = 'description'; -> Option AQuick Check:
CREATE TAG ... COMMENT = ... is correct syntax [OK]
- Using MAKE or NEW instead of CREATE
- Missing equal sign in COMMENT clause
- Using WITH instead of COMMENT
customers table?CREATE TAG pii COMMENT = 'Personally Identifiable Information'; ALTER TABLE customers SET TAG pii = 'true'; SHOW TAGS ON TABLE customers;
Solution
Step 1: Understand tag creation and assignment
The tag 'pii' is created and then assigned to the 'customers' table with value 'true'.Step 2: Check SHOW TAGS syntax and output
SHOW TAGS ON TABLE customers; lists tags assigned to the table, showing 'pii' = 'true'.Final Answer:
It will show the tag 'pii' with value 'true' assigned to the customers table -> Option AQuick Check:
SHOW TAGS ON TABLE shows assigned tags [OK]
- Thinking tags cannot be assigned to tables
- Assuming SHOW TAGS syntax is invalid
- Expecting tags without values to appear
ALTER TABLE orders SET TAG sensitive = 'yes';
What is the most likely cause of the error?
Solution
Step 1: Check if tag exists before assignment
Tags must be created with CREATE TAG before assigning to tables or columns.Step 2: Analyze error cause
If 'sensitive' tag was not created, assigning it causes an error.Final Answer:
The tag 'sensitive' was not created before assigning it -> Option CQuick Check:
Tags must exist before assignment [OK]
- Assuming any value is invalid
- Thinking ALTER TABLE can't set tags
- Believing tags only apply to columns
payments table as either 'confidential' or 'public' using tags. Which approach correctly applies tags to columns and supports data governance?Solution
Step 1: Understand tagging granularity
Tags can be assigned to columns to classify data precisely, supporting governance.Step 2: Identify correct tagging method
Using ALTER TABLE ... ALTER COLUMN ... SET TAG applies tags to columns, enabling classification.Final Answer:
Create tags 'confidential' and 'public', then assign them to each column with ALTER TABLE ... ALTER COLUMN ... SET TAG -> Option BQuick Check:
Column-level tags enable precise data classification [OK]
- Tagging only tables loses column-level detail
- Using comments instead of tags for governance
- Assigning tags to schemas instead of columns
Ready to prove it?
Pass the test and this pattern moves unknown
