@@ -41,12 +41,13 @@ This example illustrates the process of setting up a masking policy to selective
41
41
``` sql
42
42
-- Create a table and insert sample data
43
43
CREATE TABLE user_info (
44
- id INT ,
45
- email STRING
44
+ user_id INT ,
45
+ phone VARCHAR ,
46
+ email VARCHAR
46
47
);
47
48
48
- INSERT INTO user_info (
id, email)
VALUES (
1 ,
' [email protected] ' );
49
- INSERT INTO user_info (
id, email)
VALUES (
2 ,
' [email protected] ' );
49
+ INSERT INTO user_info (
user_id, phone, email)
VALUES (
1 , ' 91234567 ' ,
' [email protected] ' );
50
+ INSERT INTO user_info (
user_id, phone, email)
VALUES (
2 , ' 81234567 ' ,
' [email protected] ' );
50
51
51
52
-- Create a role
52
53
CREATE ROLE ' MANAGERS' ;
69
70
END
70
71
COMMENT = ' hide_email' ;
71
72
73
+ CREATE MASKING POLICY phone_mask AS (val nullable(string)) RETURNS nullable(string) - > CASE
74
+ WHEN current_role() IN (' MANAGERS' ) THEN val
75
+ ELSE ' *********'
76
+ END COMMENT = ' hide_phone' ;
77
+
72
78
-- Associate the masking policy with the 'email' column
73
79
ALTER TABLE user_info MODIFY COLUMN email SET MASKING POLICY email_mask;
74
80
81
+ -- Associate the masking policy with the 'phone' column
82
+ ALTER TABLE user_info MODIFY COLUMN phone SET MASKING POLICY phone_mask;
83
+
75
84
-- Query with the Root user
76
85
SELECT * FROM user_info;
77
86
78
- id|email |
79
- -- +---------+
80
- 2 |********* |
81
- 1 |********* |
82
- ```
87
+ user_id │ phone │ email │
88
+ Nullable(Int32) │ Nullable(String) │ Nullable(String) │
89
+ ─────────────────┼──────────────────┼──────────────────┤
90
+ 2 │ ********* │ ********* │
91
+ 1 │ ********* │ ********* │
92
+
93
+ ```
0 commit comments