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

feature/api-updates #33

Merged
merged 14 commits into from
Jul 12, 2023
6 changes: 3 additions & 3 deletions macros/get_lead_columns.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

{% set columns = [
{"name": "_fivetran_synced", "datatype": dbt.type_timestamp()},
{"name": "created_at", "datatype": dbt.type_timestamp()},
{"name": "created_at", "datatype": dbt.type_timestamp(), "alias": "created_timestamp"},
{"name": "email", "datatype": dbt.type_string()},
{"name": "first_name", "datatype": dbt.type_string()},
{"name": "id", "datatype": dbt.type_int()},
{"name": "id", "datatype": dbt.type_int(), "alias": "lead_id"},
{"name": "last_name", "datatype": dbt.type_string()},
{"name": "updated_at", "datatype": dbt.type_timestamp()}
{"name": "updated_at", "datatype": dbt.type_timestamp(), "alias": "updated_timestamp"}
] %}

{{ return(columns) }}
Expand Down
22 changes: 8 additions & 14 deletions models/stg_marketo__lead.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,16 @@ with base as (
staging_columns=get_lead_columns()
)
}}
-- This will check if there are non-default columns to bring in
{% set default_cols = ['id', 'created_at', 'updated_at', 'email', 'first_name', 'last_name'] %}
fivetran-catfritz marked this conversation as resolved.
Show resolved Hide resolved
{% set new_cols = dbt_utils.star(from=ref('stg_marketo__lead_tmp'), except=default_cols) %}
{% if new_cols != '/* no columns returned from star() macro */' %}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is really neat! We definitely will want to keep an eye on this macro in the dependent package to ensure this string doesn't change in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah... I didn't like hard coding the list, but when I tried to fetch the names dynamically like you did in Hubspot, the double quotes were surprisingly hard to deal with. I opted to do the hard code rather than lines and lines of code to replace the double quotes with single quotes needed for dbt_utils.star.

,{{ new_cols }}
{% endif %}

from base

), leads as (

select
id as lead_id,
created_at as created_timestamp,
updated_at as updated_timestamp,
email,
first_name,
last_name

{{ dbt_utils.star(from=ref('stg_marketo__lead_tmp'), except=['id', 'created_at', 'updated_at', 'email', 'first_name', 'last_name']) }}

from macro
)

select *
from leads
from macro