Skip to content

Commit

Permalink
[SNOW-60,162,165] Add new columns to userprofilesnapshots (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymedina authored Dec 20, 2024
1 parent ba28178 commit 4e0530a
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Configure environment
USE SCHEMA {{database_name}}.synapse_raw; --noqa: JJ01,PRS,TMP,CP02

-- Add new column
ALTER TABLE userprofilesnapshot ADD COLUMN is_two_factor_auth_enabled BOOLEAN COMMENT 'Indicates if the user had two factor authentication enabled when the snapshot was captured.';
ALTER TABLE userprofilesnapshot ADD COLUMN industry STRING COMMENT 'The industry/discipline that this person is associated with.';
ALTER TABLE userprofilesnapshot ADD COLUMN tos_agreements VARIANT COMMENT 'Contains the list of all the term of service that the user agreed to, with their agreed on date and version.';
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- Configure environment
USE SCHEMA {{database_name}}.synapse_raw; --noqa: JJ01,PRS,TMP,CP02

-- Suspend the root task
ALTER TASK refresh_synapse_warehouse_s3_stage_task SUSPEND;

-- Suspend the child task in question
ALTER TASK userprofilesnapshot_task SUSPEND;

-- Add the new column to the child task
ALTER TASK userprofilesnapshot_task MODIFY AS
COPY INTO
userprofilesnapshot
FROM (
SELECT
$1:change_type as change_type,
$1:change_timestamp as change_timestamp,
$1:change_user_id as change_user_id,
$1:snapshot_timestamp as snapshot_timestamp,
$1:id as id,
$1:user_name as user_name,
$1:first_name as first_name,
$1:last_name as last_name,
$1:email as email,
$1:location as location,
$1:company as company,
$1:position as position,
NULLIF(
REGEXP_REPLACE(
metadata$filename,
'.*userprofilesnapshots\/snapshot_date\=(.*)\/.*', '\\1'
),
'__HIVE_DEFAULT_PARTITION__'
) as snapshot_date,
$1:created_on as created_on,
$1:is_two_factor_auth_enabled as is_two_factor_auth_enabled,
$1:industry as industry,
$1:tos_agreements as tos_agreements
from
@synapse_prod_warehouse_s3_stage/userprofilesnapshots --noqa: TMP
)
pattern = '.*userprofilesnapshots/snapshot_date=.*/.*';

-- Resume the ROOT task and its child task
SELECT SYSTEM$TASK_DEPENDENTS_ENABLE( 'refresh_synapse_warehouse_s3_stage_task' );
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
-- Configure environment
USE SCHEMA {{database_name}}.synapse_raw; --noqa: JJ01,PRS,TMP,CP02

-- Drop all records from this table but keep structure and permissions intact
TRUNCATE TABLE userprofilesnapshot;

--
COPY INTO
userprofilesnapshot
FROM (
SELECT
$1:change_type as change_type,
$1:change_timestamp as change_timestamp,
$1:change_user_id as change_user_id,
$1:snapshot_timestamp as snapshot_timestamp,
$1:id as id,
$1:user_name as user_name,
$1:first_name as first_name,
$1:last_name as last_name,
$1:email as email,
$1:location as location,
$1:company as company,
$1:position as position,
NULLIF(
REGEXP_REPLACE(
metadata$filename,
'.*userprofilesnapshots\/snapshot_date\=(.*)\/.*', '\\1'
),
'__HIVE_DEFAULT_PARTITION__'
) as snapshot_date,
$1:created_on as created_on,
$1:is_two_factor_auth_enabled as is_two_factor_auth_enabled,
$1:industry as industry,
$1:tos_agreements as tos_agreements
from
@synapse_prod_warehouse_s3_stage/userprofilesnapshots --noqa: TMP
)
pattern = '.*userprofilesnapshots/snapshot_date=.*/.*';

0 comments on commit 4e0530a

Please sign in to comment.