|
| 1 | +## Disclaimer 1 |
| 2 | +THE FUNCTIONS BELOW ARE PROVIDED BY THE TRADE DESK, INC. ("TTD") "AS IS" AND "WITH ALL FAULTS." TTD SHALL HAVE NO OBLIGATION TO UPDATE THE SNOWFLAKE FUNCTIONS. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS, TTD, OR TTD'S AFFILIATES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION SUSTAINED BY YOU OR ANY THIRD PARTY) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THESE FUNCTIONS, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 3 | + |
| 4 | +## Disclaimer 2 |
| 5 | +- Instructions and functions provided are *examples only*, and not a complete implementation. |
| 6 | +- Remember to consider the privacy aspects of what is being implemented, including checking Legal/Compliance requirements about user consent and use of DII. |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | +## Begin Workflow |
| 11 | +--When testing this workflow for the first time, use Drop Table queries. Otherwise, ignore. |
| 12 | + |
| 13 | +```sql |
| 14 | + |
| 15 | + |
| 16 | +--When testing this workflow for the first time, use Drop Table queries. Otherwise, ignore. |
| 17 | + |
| 18 | +Drop Table UID_Test_Audience_March2025 |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +--Create a new table to store Email addresses |
| 25 | +Create Table UID_Test_Audience_March2025 ( ID INTEGER, EMAIL varchar(128)) |
| 26 | + |
| 27 | +-- Retrieve emails (or hashed emails) from your CDP or CRM platform |
| 28 | +INSERT INTO UID_Test_Audience_March2025 |
| 29 | +VALUES |
| 30 | +(1,'dummy1@demo.com'), |
| 31 | +(2,'dummy2@demo.com'), |
| 32 | +(3,'dummy3@demo.com'), |
| 33 | +(4,'dummy4@demo.com'), |
| 34 | +(5,'dummy5@demo.com'), |
| 35 | +(6,'dummy6@demo.com'), |
| 36 | +(7,'dummy7@demo.com'), |
| 37 | +(8,'dummy8@demo.com'), |
| 38 | +(9,'dummy9@demo.com'), |
| 39 | +(10,'dummy10@demo.com') |
| 40 | + |
| 41 | +--Query Table to confirm the emails are in your table |
| 42 | +select * from UID_Test_Audience_March2025 |
| 43 | + |
| 44 | +-- new share name: UID2_INTEG_UID_SH |
| 45 | + |
| 46 | + |
| 47 | +--Ignore for demo purposes. |
| 48 | +Drop Table UID_Test_Audience_March2025_withUID |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | +--Create new empty table with emails, and 2 more columns to collect UID and Bucket ID. This step is in here to illustrate the progression of adding in UIDs and BucketIds |
| 54 | +Create Table UID_Test_Audience_March2025_withUID ( ID INTEGER, EMAIL varchar(128), UID2 text, Bucket_ID text) |
| 55 | + |
| 56 | + |
| 57 | +--Retrieve UID and bucket ID and insert into a new table, leveraging the functions from the integration guide to map your emails to UID2s |
| 58 | +Insert into UID_Test_Audience_March2025_withUID |
| 59 | +select a.ID, a.EMAIL, m.UID, m.BUCKET_ID from UID_Test_Audience_March2025 a LEFT JOIN( |
| 60 | + select ID, t.* from UID_Test_Audience_March2025, lateral UID2_INTEG_UID_SH.UID.FN_T_IDENTITY_MAP(EMAIL, 'email') t) m |
| 61 | + on a.ID=m.ID; |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | +--Confirm the values that now exist in your new table -- now you have mapped emails and can use your UID2s! |
| 67 | +select * from UID_Test_Audience_March2025_withUID |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | +--ignore for demo |
| 72 | +Drop Table UID_Test_Audience_March2025_withUID_withRetrieved |
| 73 | + |
| 74 | + |
| 75 | +--testing-- |
| 76 | + |
| 77 | +Create Table UID_Test_Audience_March2025_withUID_withRetrieved ( ID INTEGER, EMAIL varchar(128), UID2 text, Bucket_ID text, Last_Retrieved_date TIMESTAMP_NTZ) |
| 78 | + |
| 79 | + |
| 80 | +--Create a new table with Last updated timestamp: this inserts the Current Timestamp - This has 5 columns |
| 81 | +Insert into UID_Test_Audience_March2025_withUID_withRetrieved |
| 82 | +select a.ID, a.EMAIL, m.UID, m.BUCKET_ID, CURRENT_TIMESTAMP from UID_Test_Audience_March2025 a LEFT JOIN( |
| 83 | + select ID, t.* from UID_Test_Audience_March2025, lateral UID2_INTEG_UID_SH.UID.FN_T_IDENTITY_MAP(EMAIL, 'email') t) m |
| 84 | + on a.ID=m.ID; |
| 85 | + |
| 86 | + |
| 87 | +--Confirm the values in your new table |
| 88 | +select * from UID_Test_Audience_March2025_withUID_withRetrieved |
| 89 | + |
| 90 | + |
| 91 | +--Check last salt bucket rotataion for your UID2 |
| 92 | +select a.*, b.LAST_SALT_UPDATE_UTC |
| 93 | + from UID_Test_Audience_March2025_withUID a LEFT OUTER JOIN UID2_INTEG_UID_SH.UID.SALT_BUCKETS b |
| 94 | + on a.BUCKET_ID=b.BUCKET_ID |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | +--This last query compares last retrieved date to last salt bucket Id rotation to show you the UID2 that need to be regenerated |
| 100 | +--A good way to remember this is: Whenever UID2 retrieved date is OLDER than last bucket Id rotation, then UID2 needs to be regenerated |
| 101 | +select a.*, b.LAST_SALT_UPDATE_UTC |
| 102 | + from UID_Test_Audience_March2025_withUID_withRetrieved a LEFT OUTER JOIN UID2_INTEG_UID_SH.UID.SALT_BUCKETS b |
| 103 | + on a.BUCKET_ID=b.BUCKET_ID |
| 104 | + where a.Last_Retrieved_date < b.LAST_SALT_UPDATE_UTC or a.UID2 IS NULL; |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | + |
| 109 | +---to see results of the query when the uid2 does not need to be generated, change where clause to: where a.Last_Retrieved_date < b.LAST_SALT_UPDATE_UTC or a.UID2 IS NOT NULL; -- this just shows you full results to populate the columns |
| 110 | +--where you should see that last_retrieved is NEWER than last_salt_update |
| 111 | + |
| 112 | + |
0 commit comments