Skip to content

Commit

Permalink
Exclude column from latest table
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasyu888 committed Oct 17, 2023
1 parent f98fedc commit 0bb5226
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
6 changes: 0 additions & 6 deletions admin/roles.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ TO ROLE useradmin;
GRANT ROLE AD
TO USER "[email protected]";

// Public role
// Synapse data warehouse
// GRANT SELECT ON ALL TABLES IN SCHEMA synapse_data_warehouse.synapse TO ROLE PUBLIC;
-- TODO: Add these back in after governance
-- GRANT SELECT ON FUTURE TABLES IN SCHEMA synapse_data_warehouse.synapse
-- TO ROLE PUBLIC;
USE ROLE USERADMIN;
CREATE ROLE IF NOT EXISTS masking_admin;
GRANT ROLE masking_admin
Expand Down
13 changes: 12 additions & 1 deletion admin/synapse_setup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ CREATE STAGE IF NOT EXISTS synapse_prod_warehouse_s3_stage
ALTER STAGE IF EXISTS synapse_prod_warehouse_s3_stage REFRESH;

USE ROLE SECURITYADMIN;

GRANT CREATE MASKING POLICY ON SCHEMA SYNAPSE_DATA_WAREHOUSE.synapse
TO ROLE masking_admin;
GRANT CREATE SCHEMA, USAGE ON DATABASE SYNAPSE_DATA_WAREHOUSE
Expand All @@ -63,3 +62,15 @@ GRANT ALL PRIVILEGES ON FUTURE SCHEMAS IN DATABASE SYNAPSE_DATA_WAREHOUSE
TO ROLE data_engineer;
GRANT ALL PRIVILEGES ON FUTURE TABLES IN DATABASE SYNAPSE_DATA_WAREHOUSE
TO ROLE data_engineer;

// Public role
// Synapse data warehouse
GRANT USAGE ON SCHEMA synapse_data_warehouse.synapse
TO ROLE PUBLIC;
GRANT SELECT ON TABLE synapse_data_warehouse.synapse.userprofile_latest
TO ROLE PUBLIC;

// GRANT SELECT ON ALL TABLES IN SCHEMA synapse_data_warehouse.synapse TO ROLE PUBLIC;
-- TODO: Add these back in after governance
-- GRANT SELECT ON FUTURE TABLES IN SCHEMA synapse_data_warehouse.synapse
-- TO ROLE PUBLIC;
14 changes: 8 additions & 6 deletions elt/synapse_gold.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@ CREATE VIEW IF NOT EXISTS synapse_data_warehouse.synapse.user_certified AS
;

// Use a window function to get the latest user profile snapshot and create a table
CREATE TABLE IF NOT EXISTS synapse_data_warehouse.synapse.userprofile_latest as WITH
CREATE OR REPLACE TABLE synapse_data_warehouse.synapse.userprofile_latest as WITH
RANKED_NODES AS (
SELECT
s.*
, "row_number"() OVER (PARTITION BY s.id ORDER BY change_timestamp DESC, snapshot_timestamp DESC) n
s.*
, "row_number"() OVER (PARTITION BY s.id ORDER BY change_timestamp DESC, snapshot_timestamp DESC) n
FROM
synapse_data_warehouse.synapse_raw.userprofilesnapshot s
WHERE (s.snapshot_date >= current_timestamp - INTERVAL '60 DAYS')
synapse_data_warehouse.synapse_raw.userprofilesnapshot s
WHERE
(s.snapshot_date >= current_timestamp - INTERVAL '60 DAYS') and
CHANGE_TYPE != 'DELETE'
)
SELECT *
SELECT * EXCLUDE n
FROM RANKED_NODES
where n = 1;
use role masking_admin;
Expand Down

0 comments on commit 0bb5226

Please sign in to comment.