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

Fix column declaration and enhance regexp_like support for Snowflake #107

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: 'synthea_omop_etl'
version: '0.1.0'
name: "synthea_omop_etl"
version: "0.1.0"
config-version: 2

profile: 'synthea_omop_etl'
profile: "synthea_omop_etl"

asset-paths: ["assets"]
docs-paths: ["docs"]
Expand All @@ -13,7 +13,7 @@ seed-paths: ["seeds"]
macro-paths: ["macros"]
snapshot-paths: ["snapshots"]

clean-targets: # directories to be removed by `dbt clean`
clean-targets: # directories to be removed by `dbt clean`
- "target"

vars:
Expand All @@ -34,3 +34,4 @@ seeds:
synthea:
+enabled: true
+schema: synthea_seeds
+quote_columns: true
11 changes: 11 additions & 0 deletions macros/regexp_like.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{%- macro regexp_like(subject, pattern) -%}
{{ return(adapter.dispatch("regexp_like")(subject, pattern)) }}
{%- endmacro -%}

{% macro default__regexp_like(subject, pattern) %}
{{ subject }} ~ '{{ pattern }}'
{% endmacro %}

{% macro snowflake__regexp_like(subject, pattern) %}
regexp_like({{ subject }}, '{{ pattern }}')
{% endmacro %}
2 changes: 1 addition & 1 deletion models/omop/measurement.sql
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ WITH snomed_measurements AS (
, 32827 AS measurement_type_concept_id
, 0 AS operator_concept_id
, CASE
WHEN o.observation_value ~ '^[-+]?[0-9]+\.?[0-9]*$'
WHEN {{ regexp_like("o.observation_value", "^[-+]?[0-9]+\.?[0-9]*$") }}
THEN {{ dbt.cast("o.observation_value", api.Column.translate_type("decimal")) }}
ELSE {{ dbt.cast("null", api.Column.translate_type("decimal")) }}
END AS value_as_number
Comment on lines 59 to 63
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the new macro is useful and we should keep it for future use (thanks!!!) - but looking at this gross regex, maybe we could use safe_cast here instead? https://docs.getdbt.com/reference/dbt-jinja-functions/cross-database-macros#safe_cast

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@katy-sadowski Had another look through the cross-DB macros and fairly sure there's no regular expression oriented ones sadly - I don't think there is a way around this without using custom dispatchers / macros like this

It raises the question of do we event want to add ❄️ support! I think it is nice to have - just wish they used the ~ operator...

I looked into transpiring with SQLGlot, but I think thats a lot of work for relatively low yield - pulling out the DAG from dbt etc as per here #39 (comment) is quite a lot of work which isn't in the scope of the project (IMHO!)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhh sorry i forgot about what you already said in #68 about safe_cast not being supported on all platforms. let's carry on with the regex approach! agree re: sqlglot.

Expand Down
18 changes: 9 additions & 9 deletions seeds/synthea/_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ seeds:
- name: careplans
config:
column_types:
ID: varchar
Id: varchar
START: date
STOP: date
PATIENT: varchar
Expand All @@ -32,7 +32,7 @@ seeds:
- name: claims
config:
column_types:
ID: varchar
Id: varchar
PATIENTID: varchar
PROVIDERID: varchar
PRIMARYPATIENTINSURANCEID: varchar
Expand Down Expand Up @@ -66,7 +66,7 @@ seeds:
- name: claims_transactions
config:
column_types:
ID: varchar
Id: varchar
CLAIMID: varchar
CHARGEID: integer
PATIENTID: varchar
Expand Down Expand Up @@ -121,7 +121,7 @@ seeds:
- name: encounters
config:
column_types:
ID: varchar
Id: varchar
START: timestamp
STOP: timestamp
PATIENT: varchar
Expand All @@ -139,7 +139,7 @@ seeds:
- name: imaging_studies
config:
column_types:
ID: varchar
Id: varchar
DATE: timestamp
PATIENT: varchar
ENCOUNTER: varchar
Expand Down Expand Up @@ -192,7 +192,7 @@ seeds:
- name: organizations
config:
column_types:
ID: varchar
Id: varchar
NAME: varchar
ADDRESS: varchar
CITY: varchar
Expand All @@ -206,7 +206,7 @@ seeds:
- name: patients
config:
column_types:
ID: varchar
Id: varchar
BIRTHDATE: date
DEATHDATE: date
SSN: varchar
Expand Down Expand Up @@ -245,7 +245,7 @@ seeds:
- name: payers
config:
column_types:
ID: varchar
Id: varchar
NAME: varchar
ADDRESS: varchar
CITY: varchar
Expand Down Expand Up @@ -281,7 +281,7 @@ seeds:
- name: providers
config:
column_types:
ID: varchar
Id: varchar
ORGANIZATION: varchar
NAME: varchar
GENDER: varchar
Expand Down