Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added raw schema link between Library hub to ExternalSubject hub #3

Merged
merged 1 commit into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions orcavault/models/raw/link_library_external_subject.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
with source as (

select library_id, external_subject_id from {{ source('ods', 'data_portal_labmetadata') }}
union
select library_id, external_subject_id from {{ source('ods', 'data_portal_limsrow') }}
union
select lib.library_id as library_id, sbj.subject_id as external_subject_id from {{ source('ods', 'metadata_manager_library') }} as lib
join {{ source('ods', 'metadata_manager_subject') }} as sbj on sbj.orcabus_id = lib.subject_orcabus_id

),

cleaned as (

select
distinct library_id, trim(external_subject_id) as external_subject_id
from
source
where
(library_id is not null and library_id <> '') and
(external_subject_id is not null and external_subject_id <> '')

),

transformed as (

select
encode(sha256(cast(external_subject_id as bytea)), 'hex') as external_subject_hk,
encode(sha256(cast(library_id as bytea)), 'hex') as library_hk,
cast('{{ run_started_at }}' as timestamptz) as load_datetime,
(select 'lab') as record_source
from
cleaned

),

final as (

select
encode(sha256(concat(external_subject_hk, library_hk)::bytea), 'hex') as library_external_subject_hk,
external_subject_hk,
library_hk,
load_datetime,
record_source
from
transformed

)

select * from final
26 changes: 26 additions & 0 deletions orcavault/models/raw/link_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,32 @@ models:
- name: record_source
data_type: varchar(255)

- name: link_library_external_subject
config:
contract: { enforced: true }
constraints:
- type: primary_key
columns: [ library_external_subject_hk ]
- type: foreign_key
columns: [ external_subject_hk ]
to: ref('hub_external_subject')
to_columns: [ external_subject_hk ]
- type: foreign_key
columns: [ library_hk ]
to: ref('hub_library')
to_columns: [ library_hk ]
columns:
- name: library_external_subject_hk
data_type: char(64)
- name: external_subject_hk
data_type: char(64)
- name: library_hk
data_type: char(64)
- name: load_datetime
data_type: timestamptz
- name: record_source
data_type: varchar(255)

- name: link_library_experiment
config:
contract: { enforced: true }
Expand Down
Loading