Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanBaker committed Apr 28, 2020
0 parents commit 558c193
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
target/
dbt_modules/
logs/
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Welcome to your new dbt project!

### Using the starter project

Try running the following commands:
- dbt run
- dbt test


### Resources:
- Learn more about dbt [in the docs](https://docs.getdbt.com/docs/introduction)
- Check out [Discourse](https://discourse.getdbt.com/) for commonly asked questions and answers
- Join the [chat](http://slack.getdbt.com/) on Slack for live discussions and support
- Find [dbt events](https://events.getdbt.com) near you
- Check out [the blog](https://blog.getdbt.com/) for the latest news on dbt's development and best practices
14 changes: 14 additions & 0 deletions dbt_project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: 'marketo'
version: '1.0.0'

source-paths: ["models"]
analysis-paths: ["analysis"]
test-paths: ["tests"]
data-paths: ["data"]
macro-paths: ["macros"]
snapshot-paths: ["snapshots"]

target-path: "target" # directory which will store compiled SQL files
clean-targets: # directories to be removed by `dbt clean`
- "target"
- "dbt_modules"
Empty file added macros/.gitkeep
Empty file.
22 changes: 22 additions & 0 deletions models/base/stg_activity_change_data_value.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
with base as (

select *
from {{ var('activity_change_data_value') }}
where lead_id = 29616

), fields as (

select
id,
activity_date,
lead_id,
new_value,
old_value,
primary_attribute_value,
primary_attribute_value_id
from base

)

select *
from fields
16 changes: 16 additions & 0 deletions models/base/stg_lead_describe.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
with base as (

select *
from {{ var('lead_describe') }}

), fields as (

select
id,
restname
from base

)

select *
from fields
63 changes: 63 additions & 0 deletions models/intermediate/change_data_value_pivot.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{% set results = run_query('select restname from ' ~ ref('stg_lead_describe')) %}

{% if execute %}
{# Return the first column #}
{% set results_list = results.columns[0].values() %}
{% else %}
{% set results_list = [] %}
{% endif %}

with change_data as (

select *
from {{ ref('stg_activity_change_data_value') }}

), lead_describe as (

select *
from {{ ref('stg_lead_describe') }}

), joined as (

select
change_data.*,
lead_describe.restname as primary_attribute_column
from change_data
left join lead_describe
on change_data.primary_attribute_value_id = lead_describe.id

), event_order as (

select
*,
row_number() over (
partition by cast(activity_date as date), lead_id, primary_attribute_value_id
order by activity_date asc
) as row_num
from joined

), filtered as (

select *
from event_order
where row_num = 1

), pivot as (

select
cast(activity_date as date) as date_day,
lead_id,

{% for col in results_list %}
{% set col_xf = col|lower|replace("__c","_c") %}
min(case when lower(primary_attribute_column) = '{{ col_xf }}' then new_value end) as {{ col_xf }}
{% if not loop.last %} , {% endif %}
{% endfor %}

from filtered
group by 1,2

)

select *
from pivot
3 changes: 3 additions & 0 deletions packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages:
- package: fishtown-analytics/dbt_utils
version: 0.3.0
Empty file added tests/.gitkeep
Empty file.

0 comments on commit 558c193

Please sign in to comment.