-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from umccr/add-int-to-ext-smp-link
Added raw schema link between Sample hub to ExternalSample hub
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
with source as ( | ||
|
||
select sample_id, external_sample_id from {{ source('ods', 'data_portal_labmetadata') }} | ||
union | ||
select sample_id, external_sample_id from {{ source('ods', 'data_portal_limsrow') }} | ||
union | ||
select sample_id, external_sample_id from {{ source('ods', 'metadata_manager_sample') }} | ||
|
||
), | ||
|
||
cleaned as ( | ||
|
||
select | ||
distinct sample_id, trim(external_sample_id) as external_sample_id | ||
from | ||
source | ||
where | ||
(sample_id is not null and sample_id <> '') and | ||
(external_sample_id is not null and external_sample_id <> '') | ||
|
||
), | ||
|
||
transformed as ( | ||
|
||
select | ||
encode(sha256(cast(external_sample_id as bytea)), 'hex') as external_sample_hk, | ||
encode(sha256(cast(sample_id as bytea)), 'hex') as sample_hk, | ||
cast('{{ run_started_at }}' as timestamptz) as load_datetime, | ||
(select 'lab') as record_source | ||
from | ||
cleaned | ||
|
||
), | ||
|
||
final as ( | ||
|
||
select | ||
encode(sha256(concat(external_sample_hk, sample_hk)::bytea), 'hex') as internal_external_sample_hk, | ||
external_sample_hk, | ||
sample_hk, | ||
load_datetime, | ||
record_source | ||
from | ||
transformed | ||
|
||
) | ||
|
||
select * from final |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters