Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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: 0 additions & 9 deletions README.md

This file was deleted.

4 changes: 4 additions & 0 deletions greenery/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

target/
dbt_packages/
logs/
164 changes: 164 additions & 0 deletions greenery/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# WEEK 3



## PART 1
** What is ur overall cnversion rate?

````sql
with conversion_rate as
(
select
product_id,
name,
cast(count(distinct (case when event_type='add_to_cart' then session_id end)) as float) as check_out,
cast(count(distinct session_id) as float) as sessions

from
dbt.dbt_sofia.stg_greenery_events
left join dbt.dbt_sofia.stg_greenery_products using( product_id)

group by 1,2 )

select
product_id,
name,
sum(check_out)/sum(sessions) as cr from conversion_rate
group by 1,2
````
** What is ur overall cnversion rate by product?
````slq

with conversion_rate as
(
select
product_id,
name,
cast(count(distinct (case when event_type='add_to_cart' then session_id end)) as float) as check_out,
cast(count(distinct session_id) as float) as sessions

from
dbt.dbt_sofia.stg_greenery_events
left join dbt.dbt_sofia.stg_greenery_products using( product_id)

group by 1,2 )

select
product_id,
name,
sum(check_out)/sum(sessions) as cr from conversion_rate
group by 1,2
````

<img width="186" alt="image" src="https://user-images.githubusercontent.com/106842349/175751123-36ff4aab-88cc-40b7-9bb6-bc2fd5938bdf.png">

*** PART 2
macro used in models/mart/product/event_type_per_sesssion.sql
````sql
{% macro get_column_values(column_name, relation) %}

{% set relation_query %}
select distinct
{{ column_name }}
from {{ relation }}
order by 1
{% endset %}

{% set results = run_query(relation_query) %}

{% if execute %}
{% set results_list = results.columns[0].values() %}
{% else %}
{% set results_list = [] %}
{% endif %}

{{ return(results_list) }}

{% endmacro %}


{% macro get_payment_methods() %}

{{ return(get_column_values('event_type', ref('stg_greenery_events'))) }}

{% endmacro %}
````
***PART 4
macro used in models/mart/product/event_type_per_sesssion_version2.sql
````sql
{%- set event_types = dbt_utils.get_column_values(
table=ref('stg_greenery_events'),
column='event_type'
) -%}

select
session_id,
{%- for event_type in event_types %}
sum(case when event_type = '{{event_type}}' then 1 end) as {{event_type}}_count
{%- if not loop.last %},{% endif -%}
{% endfor %}
from {{ ref('stg_greenery_events') }}
group by 1

````
# WEEK 4

## PART1
````sql
{% snapshot orders_snapshot%}
{{
config(
target_schema='snapshots'
, strategy= 'check'
,unique_key= 'order_id'
, check_cols=['status']
)
}}

select * from {{ source ('src_greenery','orders')}}

{% endsnapshot %}
````
## PART 2
Usng greeneery/models/mart/product/intermidiate/init_funnel.sql
and greeneery/models/mart/product/intermidiate/fct_funnel.sql

How are our users moving through the product funnel?

<img width="787" alt="image" src="https://user-images.githubusercontent.com/106842349/176567182-231af317-e7cc-44b3-a288-b216e57ab895.png">

Which steps in the funnel have largest drop off points?

- from first to second

### exposures:
````sql
version: 2

exposures:

- name: tableu_dash
type: dashboard
maturity: medium
url: https://tableau.io
description: >
all of the data
depends_on:
- ref('fct_funnel')

owner:
name: sofi
email: [email protected]

````

## Part3

- My company is already implementing dbt , but is not ready yet. I think the combination of jinja and macros can automate a lot of things and give us a lot of independance.

### 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](https://community.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
Empty file added greenery/analyses/.gitkeep
Empty file.
46 changes: 46 additions & 0 deletions greenery/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

# Name your project! Project names should contain only lowercase characters
# and underscores. A good package name should reflect your organization's
# name or the intended use of these models
name: 'greenery'
version: '1.0.0'
config-version: 2

# This setting configures which "profile" dbt uses for this project.
profile: 'greenery'

# These configurations specify where dbt should look for different types of files.
# The `model-paths` config, for example, states that models in this project can be
# found in the "models/" directory. You probably won't need to change these!
model-paths: ["models"]
analysis-paths: ["analyses"]
test-paths: ["tests"]
seed-paths: ["seeds"]
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_packages"


# Configuring models
# Full documentation: https://docs.getdbt.com/docs/configuring-models

# In this example config, we tell dbt to build all models in the example/ directory
# as tables. These settings can be overridden in the individual model files
# using the `{{ config(...) }}` macro.
models:
greenery:
# Config indicated by + and applies to all files under models/example/
example:
+materialized: view

post-hook:
on-run-end:
- "grant usage on schema {{ target.schema }} to role reporting"


- "grant select on all tables in schema {{ target.schema }} role reporting"

Empty file added greenery/macros/.gitkeep
Empty file.
31 changes: 31 additions & 0 deletions greenery/macros/event_types_per_session.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@




{% macro get_column_values(column_name, relation) %}

{% set relation_query %}
select distinct
{{ column_name }}
from {{ relation }}
order by 1
{% endset %}

{% set results = run_query(relation_query) %}

{% if execute %}
{% set results_list = results.columns[0].values() %}
{% else %}
{% set results_list = [] %}
{% endif %}

{{ return(results_list) }}

{% endmacro %}


{% macro get_payment_methods() %}

{{ return(get_column_values('event_type', ref('stg_greenery_events'))) }}

{% endmacro %}
16 changes: 16 additions & 0 deletions greenery/models/example/expoosure_exampl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 2

exposures:

- name: tableu_dash
type: dashboard
maturity: medium
url: https://tableau.io
description: >
all of the data
depends_on:
- ref('fct_funnel')

owner:
name: sofi
email: [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{
config(
materialized='table'
)
}}

select
stg_greenery_users.user_id,
order_cost

from {{ref('stg_greenery_users')}}
left join {{ref('stg_greenery_orders')}}
on stg_greenery_users.user_id=stg_greenery_orders.user_id
16 changes: 16 additions & 0 deletions greenery/models/example/marts/core/ltv_users.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


{{
config(
materialized='table'
)
}}

select
user_id,
sum(order_cost) as orders_cost

from {{ref('init_users_value')}}
GROUP BY 1


12 changes: 12 additions & 0 deletions greenery/models/example/marts/core/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2

models:
- name: stg_greenery_users
columns:
- name: name
tests:
- not_null
- unique



16 changes: 16 additions & 0 deletions greenery/models/example/marts/marketing/discount.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{
config(
MATERIALIZED='table'
)
}}



select
user_id,
sum(discount) acu_discount

from {{ref('init_disccount_counts')}}
group by 1


Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{
config(
materialized='table'
)
}}

select
user_id,
order_id,
stg_greenery_orders.promo_id
,discount

from {{ref('stg_greenery_orders')}}
left join {{ref('stg_greenery_promos')}}
on stg_greenery_promos.promo_id=stg_greenery_orders.promo_id

15 changes: 15 additions & 0 deletions greenery/models/example/marts/product /event_type_per_sessions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{%- set event_types = get_column_values(
column_name='event_type',
relation=ref('stg_greenery_events'),

) -%}

select
session_id,
created_at,
{%- for event_type in event_types %}
sum(case when event_type = '{{event_type}}' then 1 end) as {{event_type}}_count
{%- if not loop.last %},{% endif -%}
{% endfor %}
from {{ ref('stg_greenery_events') }}
group by 1,2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{%- set event_types = dbt_utils.get_column_values(
table=ref('stg_greenery_events'),
column='event_type'
) -%}

select
session_id,
{%- for event_type in event_types %}
sum(case when event_type = '{{event_type}}' then 1 end) as {{event_type}}_count
{%- if not loop.last %},{% endif -%}
{% endfor %}
from {{ ref('stg_greenery_events') }}
group by 1
Loading