Skip to content

Commit

Permalink
Sk/crosswalk table (#3990)
Browse files Browse the repository at this point in the history
* Created census_gsa_crosswalk materialized view

* Added census_gsa_crosswalk materialized view

* Added census_gsa_crosswalk materialized view

* Created census_gsa_crosswalk materialized view
  • Loading branch information
gsa-suk authored Jun 18, 2024
1 parent 6f559af commit af65389
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
52 changes: 52 additions & 0 deletions backend/dissemination/sql/create_materialized_views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,55 @@ CREATE INDEX IF NOT EXISTS dc_audit_year_idx

CREATE INDEX IF NOT EXISTS dc_aln_idx
on dissemination_combined (aln);


-- Census to GSA Crosswalk
CREATE SEQUENCE IF NOT EXISTS census_gsa_crosswalk_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE;

CREATE MATERIALIZED VIEW IF NOT EXISTS
census_gsa_crosswalk_temp AS
WITH dissemination_general_data_sub_temp AS
(SELECT
dg.report_id,
dg.auditee_uei,
dg.auditee_ein,
substring(dg.report_id, 1, 4) as audit_year,
ltrim(substring(dg.report_id, 16, 25), '0') as dbkey
FROM dissemination_general dg
WHERE dg.report_id ilike '%CENSUS%')
SELECT DISTINCT
nextval('census_gsa_crosswalk_id_seq') AS id,
chmr.audit_year,
chmr.dbkey,
gd.report_id,
gd.auditee_uei,
gd.auditee_ein,
chmr.run_datetime,
chmr.migration_status
FROM census_historical_migration_reportmigrationstatus chmr
INNER JOIN dissemination_general_data_sub_temp gd
ON chmr.audit_year = gd.audit_year AND chmr.dbkey = gd.dbkey
WHERE chmr.migration_status = 'SUCCESS';

DROP MATERIALIZED VIEW IF EXISTS census_gsa_crosswalk;
ALTER SEQUENCE census_gsa_crosswalk_id_seq RESTART;
ALTER MATERIALIZED VIEW census_gsa_crosswalk_temp RENAME TO census_gsa_crosswalk;

CREATE INDEX IF NOT EXISTS cg_crosswalk_report_id_idx
on census_gsa_crosswalk (report_id);

CREATE INDEX IF NOT EXISTS cg_crosswalk_audit_year_idx
on census_gsa_crosswalk (audit_year);

CREATE INDEX IF NOT EXISTS cg_crosswalk_dbkey_idx
on census_gsa_crosswalk (dbkey);

CREATE INDEX IF NOT EXISTS cg_crosswalk_auditee_uei_idx
on census_gsa_crosswalk (auditee_uei);

CREATE INDEX IF NOT EXISTS cg_crosswalk_auditee_ein_idx
on census_gsa_crosswalk (auditee_ein);
4 changes: 4 additions & 0 deletions backend/dissemination/sql/drop_materialized_views.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
DROP MATERIALIZED VIEW IF EXISTS dissemination_combined;

DROP SEQUENCE IF EXISTS dissemination_combined_id_seq;

DROP MATERIALIZED VIEW IF EXISTS census_gsa_crosswalk;

DROP SEQUENCE IF EXISTS census_gsa_crosswalk_id_seq;
2 changes: 2 additions & 0 deletions backend/dissemination/sql/refresh_materialized_views.sql
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
REFRESH MATERIALIZED VIEW dissemination_combined;

REFRESH MATERIALIZED VIEW census_gsa_crosswalk;

0 comments on commit af65389

Please sign in to comment.