diff --git a/README.md b/README.md index 404dc02..07ec201 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ [![Apache License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) -# Intercom Airbyte +# facebook_ads Airbyte -This package models Intercom data from [Airbyte's connector](https://airbyte.com/connectors/intercom). +This package models facebook_ads data from [Airbyte's connector](https://airbyte.com/connectors/facebook_ads). Let us know which connectors you would like to see next [here](https://19au6qz3a6s.typeform.com/to/c284SPEN) @@ -16,7 +16,7 @@ This package contains staging models, with the following naming conventions acro ## DBT Metrics -This package contains configurations for DBT metrics for you to get up and running quickly with standard Intercom metrics in your existing BI tools. +This package contains configurations for DBT metrics for you to get up and running quickly with standard facebook_ads metrics in your existing BI tools. ## Installation Instructions @@ -26,7 +26,7 @@ Include in your `packages.yml` ```yaml packages: - - package: cerebriumAI/dbt-intercom + - package: cerebriumAI/dbt-facebook_ads version: ["0.1.0"] ``` @@ -34,7 +34,7 @@ packages: ### Source Data Location -By default, this package will look for your Intercom data in the `intercom` schema of your [target database](https://docs.getdbt.com/docs/running-a-dbt-project/using-the-command-line-interface/configure-your-profile). If this is not where your Intercom data is, please add the following configuration to your `dbt_project.yml` file: +By default, this package will look for your facebook_ads data in the `facebook_ads` schema of your [target database](https://docs.getdbt.com/docs/running-a-dbt-project/using-the-command-line-interface/configure-your-profile). If this is not where your facebook_ads data is, please add the following configuration to your `dbt_project.yml` file: ```yml # dbt_project.yml @@ -42,8 +42,8 @@ By default, this package will look for your Intercom data in the `intercom` sche config-version: 2 vars: - intercom_schema: your_schema_name - intercom_database: your_database_name + facebook_ads_schema: your_schema_name + facebook_ads_database: your_database_name ``` ## Database Support diff --git a/dbt_project.yml b/dbt_project.yml index ef9889c..6e311c4 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -1,4 +1,4 @@ -name: 'airbyte_intercom' +name: 'airbyte_facebook_ads' version: '0.1.0' require-dbt-version: ['>=1.0.0'] config-version: 2 @@ -16,20 +16,16 @@ clean-targets: - "dbt_packages" models: - airbyte_intercom: + airbyte_facebook_ads: materialized: table tmp: materialized: view vars: - airbyte_intercom: - admins: "{{ source('airbyte_intercom','admins') }}" - companies: "{{ source('airbyte_intercom','companies') }}" - companies_plan: "{{ source('airbyte_intercom','companies_plan') }}" - contacts: "{{ source('airbyte_intercom','contacts') }}" - conversation_parts: "{{ source('airbyte_intercom','conversation_parts') }}" - conversations: "{{ source('airbyte_intercom','conversations') }}" - conversations_assignee: "{{ source('airbyte_intercom','conversations_assignee') }}" - conversations_conversation_rating: "{{ source('airbyte_intercom','conversations_conversation_rating') }}" - conversations_sla_applied: "{{ source('airbyte_intercom','conversations_sla_applied') }}" - conversations_statistics: "{{ source('airbyte_intercom','conversations_statistics') }}" + facebook_ads_schema: "facebook_marketing_airbyte_masch" + airbyte_facebook_ads: + ads: "{{ source('airbyte_facebook_ads','ads') }}" + ad_creative: "{{ source('airbyte_facebook_ads','ad_creative') }}" + ad_creatives: "{{ source('airbyte_facebook_ads','ad_creatives') }}" + ad_insights: "{{ source('airbyte_facebook_ads','ad_insights') }}" + campaigns: "{{ source('airbyte_facebook_ads','campaigns') }}" \ No newline at end of file diff --git a/models/facebook_ads__ad_adapter.sql b/models/facebook_ads__ad_adapter.sql new file mode 100644 index 0000000..69510b3 --- /dev/null +++ b/models/facebook_ads__ad_adapter.sql @@ -0,0 +1,29 @@ +/* + +base url +url host +url path +utm source +utm meidum +utm campaign +utm content +utm term +*/ + +with ads as ( + select + created_at_timestamp as date_day, + account_id, + account_name, + campaign_id, + campaign_name, + adset_id, + adset_name, + ad_id, + ad_name, + account_id, + impressions, + clicks, + spend + from {{ ref('stg_facebook_ads_ads') }} +), \ No newline at end of file diff --git a/models/facebook_ads__ad_set_report.sql b/models/facebook_ads__ad_set_report.sql new file mode 100644 index 0000000..f666c44 --- /dev/null +++ b/models/facebook_ads__ad_set_report.sql @@ -0,0 +1,47 @@ +/* +date_day, +account_id, +account_name, +campaign_id, +campaign_name, +adset_id, +adset_name, +clicks, +impressions, +spend +*/ + +with ads as ( + select + ad_id, + ad_name, + adset_id, + account_id, + account_name + campaign_id, + campaign_name, + created_at_timestamp, + spend, + clicks, + impressions + from {{ ref('stg_facebook_ads_ads') }} +), + +adset as ( + select + ads.created_at_timestamp, + ads.adset_id, + ads.adset_name, + ads.campaign_id, + ads.campaign_name, + ads.account_id, + ads.account_name, + sum(ads.spend), + sum(ads.clicks), + sum(ads.impressions) + from campaigns + left join ads using (campaign_id) and (created_at_timestamp) + {{ dbt_utils.group_by(n=6) }} +) + +select * from final_campaigns \ No newline at end of file diff --git a/models/facebook_ads__campaign_report.sql b/models/facebook_ads__campaign_report.sql new file mode 100644 index 0000000..983ae86 --- /dev/null +++ b/models/facebook_ads__campaign_report.sql @@ -0,0 +1,54 @@ +/* +date_day, +account_id, +account_name, +campaign_id, +campaign_name, +clicks, +impressions, +spend +*/ + +with campaigns as ( + select + id as campaign_id, + name as campaign_name, + objective, + account_id, + created_time as created_at_timestamp + from {{ ref('stg_facebook_ads_campaigns') }} +), + +ads as ( + select + ad_id, + ad_name, + adset_id, + account_id, + account_name + campaign_id, + campaign_name, + created_at_timestamp, + spend, + clicks, + impressions + from {{ ref('stg_facebook_ads_ads') }} +), + +final_campaigns as ( + select + campaigns.created_at_timestamp, + campaigns.campaign_id, + campaigns.campaign_name, + campaigns.account_id, + ads.account_name, + campaigns.objective, + sum(ads.spend), + sum(ads.clicks), + sum(ads.impressions) + from campaigns + left join ads using (campaign_id) and (created_at_timestamp) + {{ dbt_utils.group_by(n=6) }} +) + +select * from final_campaigns \ No newline at end of file diff --git a/models/intercom__admin_metrics.sql b/models/intercom__admin_metrics.sql deleted file mode 100644 index f4d8550..0000000 --- a/models/intercom__admin_metrics.sql +++ /dev/null @@ -1,57 +0,0 @@ -with conversation_metrics as ( - select * - from {{ ref('intercom__conversation_metrics') }} - where assignee_type = 'admin' -), - - admin_table as ( - select * - from {{ ref('stg_intercom__admins') }} - ), - ---Aggregates admin specific metrics. The admin in question is the one who last closed the conversations. -admin_metrics as ( - select - last_closed_by_id, - sum(case when conversation_metrics.conversation_state = 'closed' then 1 else 0 end) as total_conversations_closed, - avg(conversation_metrics.count_total_parts) as average_conversation_parts, - avg(conversation_metrics.conversation_rating) as average_conversation_rating - from conversation_metrics - - group by 1 -), - ---Generates the median values for admins who last closed conversations. -median_metrics as ( - select - last_closed_by_id, - {{ fivetran_utils.percentile("conversation_metrics.count_reopens", "last_closed_by_id", "0.5") }} as median_conversations_reopened, - {{ fivetran_utils.percentile("conversation_metrics.count_assignments", "last_closed_by_id", "0.5") }} as median_conversation_assignments, - {{ fivetran_utils.percentile("conversation_metrics.time_to_first_response_minutes", "last_closed_by_id", "0.5") }} as median_time_to_first_response_time_minutes - from conversation_metrics - - group by 1 -), - ---Joins the aggregate, and median CTEs to the admin table with team enrichment. Distinct is necessary to keep grain with median values and aggregates. -final as ( - select distinct - admin_table.admin_id, - admin_table.name as admin_name, - - admin_table.job_title, - admin_metrics.total_conversations_closed, - admin_metrics.average_conversation_parts, - admin_metrics.average_conversation_rating, - median_metrics.median_conversations_reopened, - median_metrics.median_conversation_assignments -from admin_table - -left join admin_metrics - on admin_metrics.last_closed_by_id = admin_table.admin_id - -left join median_metrics - on median_metrics.last_closed_by_id = admin_table.admin_id -) - -select * from final diff --git a/models/intercom__companies.sql b/models/intercom__companies.sql deleted file mode 100644 index 13ca3ed..0000000 --- a/models/intercom__companies.sql +++ /dev/null @@ -1,32 +0,0 @@ -with companies_plan as ( - - select distinct - _airbyte_companies_hashid, - plan_id, - plan_name - from {{ ref('stg_intercom__companies_plan' )}} - group by _airbyte_companies_hashid, plan_id, plan_name - -), - -companies as ( - - select - company_id, - company_name, - created_at_timestamp, - industry, - monthly_spend, - companies_plan.plan_id, - companies_plan.plan_name, - session_count, - updated_at_timestamp, - user_count, - website - - from {{ ref('int_intercom__latest_company') }} - left join companies_plan using (_airbyte_companies_hashid) - -) - -select * from companies diff --git a/models/intercom__contacts.sql b/models/intercom__contacts.sql deleted file mode 100644 index f264350..0000000 --- a/models/intercom__contacts.sql +++ /dev/null @@ -1,8 +0,0 @@ -select - contact_id, - name, - email, - phone, - last_seen_at_timestamp, - created_at_timestamp -from {{ ref('int_intercom__latest_contact') }} diff --git a/models/intercom__conversation_metrics.sql b/models/intercom__conversation_metrics.sql deleted file mode 100644 index 8af8df1..0000000 --- a/models/intercom__conversation_metrics.sql +++ /dev/null @@ -1,41 +0,0 @@ -with conversation_part_aggregates as ( - select * - from {{ ref('int_intercom__conversation_part_aggregates') }} -), - -conversations as( - select * - from {{ ref('intercom__conversations') }} -), - ---Returns time difference aggregates to the conversations_enhanced model. All time metrics are broken down to the second, then divided by 60 to reflect minutes without rounding errors. -final as ( - select - conversations.*, - conversation_part_aggregates.count_assignments, - conversation_part_aggregates.count_reopens, - conversation_part_aggregates.count_total_parts, - conversation_part_aggregates.first_admin_response_at, - conversation_part_aggregates.first_assignment_at, - conversation_part_aggregates.first_contact_reply_at, - conversation_part_aggregates.first_reopen_at, - conversation_part_aggregates.last_admin_response_at, - conversation_part_aggregates.last_assignment_at, - conversation_part_aggregates.last_contact_reply_at, - conversation_part_aggregates.last_reopen_at, - - ({{ dbt_utils.datediff("conversations.created_at_date", "conversation_part_aggregates.first_assignment_at", 'second') }} /60) as time_to_first_assignment_minutes, - - ({{ dbt_utils.datediff("conversations.created_at_date", "conversation_part_aggregates.first_admin_response_at", 'second') }} /60) as time_to_first_response_minutes, - - ({{ dbt_utils.datediff("conversations.created_at_date", "conversation_part_aggregates.last_assignment_at", 'second') }} /60) as time_to_last_assignment_minutes - - from conversation_part_aggregates - - left join conversations - on conversations.conversation_id = conversation_part_aggregates.conversation_id - -) - -select * -from final diff --git a/models/intercom__conversations.sql b/models/intercom__conversations.sql deleted file mode 100644 index a91b23f..0000000 --- a/models/intercom__conversations.sql +++ /dev/null @@ -1,29 +0,0 @@ -with latest_conversation as ( - select * - from {{ ref('int_intercom__latest_conversation') }} -), - -conversations as ( - - select - conversation_id, - created_at_timestamp, - updated_at_timestamp, - created_at_date, - updated_at_date, - conversation_type, - conversation_title, - conversation_state, - is_read, - conversation_rating_value as conversation_rating, - conversation_remark, - sla_name, - sla_status, - assignee_type, - last_closed_by_id - - from latest_conversation - -) - -select * from conversations diff --git a/models/schema.yml b/models/schema.yml index 04bb6f1..2726be1 100644 --- a/models/schema.yml +++ b/models/schema.yml @@ -1,7 +1,17 @@ version: 2 +sources: + - name: airbyte_facebook_ads + schema: "{{ var('facebook_ads_schema', 'facebook_marketing_airbyte_masch') }}" + database: "{% if target.type != 'spark'%}{{ var('facebook_ads_database', target.database) }}{% endif %}" + tables: + - name: ads + - name: ad_creative + - name: ad_creatives + - name: ad_insights + - name: campaigns models: - - name: intercom__admin_metrics + - name: facebook_ads__admin_metrics description: > Each record represents an individual admin (employee) and a unique team they are assigned on, enriched with admin specific conversation aggregates. For example, the admin's total conversations, average rating, and median response times by specific team. columns: @@ -28,12 +38,12 @@ models: - name: median_time_to_last_close_minutes description: The admins median value of time it took to the last closure of a conversation. - - name: intercom__companies + - name: facebook_ads__companies description: > Each record represents a single company, enriched with data related to the company industry, monthly_spend, and user_count. columns: - name: company_id - description: The unique identifier representing the historical Intercom defined company. + description: The unique identifier representing the historical facebook_ads defined company. tests: - not_null - unique @@ -58,13 +68,13 @@ models: - name: updated_at_timestamp description: The time the company was last updated at. - - name: intercom__contacts + - name: facebook_ads__contacts description: > Each record represents a single contact, enriched with data identifying the contacts role, if they have unsubscribed from the email list, last contacted information, and which company they belong to. columns: - name: contact_id - description: The unique identifier for the contact which is given by Intercom. + description: The unique identifier for the contact which is given by facebook_ads. tests: - not_null - unique @@ -73,7 +83,7 @@ models: - name: admin_id description: The unique identifier representing the admin which has been assigned ownership of the contact. - name: created_at_timestamp - description: The time when the contact was created within Intercom. + description: The time when the contact was created within facebook_ads. - name: updated_at_timestamp description: The time when the contact was last updated. - name: signed_up_at_timestamp @@ -95,7 +105,7 @@ models: - name: all_contact_company_names description: String aggregation of all companies the contact is associated with. - - name: intercom__conversations + - name: facebook_ads__conversations description: > Each record represents a single conversation, enriched with data from the multiple conversation parts. The conversation parts provide relevant information such as who was assigned to the conversation, which contact the conversation was with, @@ -127,9 +137,9 @@ models: - name: is_read description: Boolean indicating whether the conversation message has been read. - - name: intercom__conversation_metrics + - name: facebook_ads__conversation_metrics description: > - Each record represents a single row from intercom__conversation_enhanced, enriched with aggregates which determine + Each record represents a single row from facebook_ads__conversation_enhanced, enriched with aggregates which determine time to first response, time to first close, and time to last close. columns: - name: count_reopens @@ -221,9 +231,9 @@ models: description: An optional field to add a remark to correspond to the number rating. sources: - - name: airbyte_intercom - schema: "{{ var('intercom_schema', 'intercom') }}" - database: "{% if target.type != 'spark'%}{{ var('intercom_database', target.database) }}{% endif %}" + - name: airbyte_facebook_ads + schema: "{{ var('facebook_ads_schema', 'facebook_ads') }}" + database: "{% if target.type != 'spark'%}{{ var('facebook_ads_database', target.database) }}{% endif %}" tables: - name: admins - name: companies @@ -239,7 +249,7 @@ sources: metrics: - name: number_of_contacts label: Number of contacts - model: ref('intercom__contacts') + model: ref('facebook_ads__contacts') description: "The number of contacts" type: count @@ -250,7 +260,7 @@ metrics: - name: number_of_conversations label: Number of conversations - model: ref('intercom__conversations') + model: ref('facebook_ads__conversations') description: "The number of conversations" type: count @@ -267,7 +277,7 @@ metrics: - name: average_time_to_first_assignment_minutes label: Average time to first assignment minutes - model: ref('intercom__conversation_metrics') + model: ref('facebook_ads__conversation_metrics') description: "The average time to first assignment minutes" type: average @@ -278,7 +288,7 @@ metrics: - name: average_time_to_first_response_minutes label: Average time to first response minutes - model: ref('intercom__conversation_metrics') + model: ref('facebook_ads__conversation_metrics') description: "The average time to first response minutes" type: average @@ -289,7 +299,7 @@ metrics: - name: average_conversation_rating label: Average conversation rating - model: ref('intercom__conversations') + model: ref('facebook_ads__conversations') description: "The average conversation rating" type: average diff --git a/models/tmp/int_intercom__conversation_part_aggregates.sql b/models/tmp/int_intercom__conversation_part_aggregates.sql deleted file mode 100644 index 93d8988..0000000 --- a/models/tmp/int_intercom__conversation_part_aggregates.sql +++ /dev/null @@ -1,37 +0,0 @@ -with conversation_parts as ( - select * - from {{ ref('stg_intercom__conversation_parts') }} -), - -latest_conversation as ( - select * - from {{ ref('int_intercom__latest_conversation') }} - ), - ---Aggregates conversation part data related to a single conversation from the int_intercom__latest_conversation model. See below for specific aggregates. -final as ( - select - latest_conversation.conversation_id, - latest_conversation.created_at_date as conversation_created_at_date, - count(conversation_parts.conversation_part_id) as count_total_parts, - min(case when conversation_parts.part_type = 'comment' and conversation_parts.author_type in ('lead','user') then conversation_parts.created_at_date else null end) as first_contact_reply_at, - min(case when conversation_parts.part_type like '%assignment%' then conversation_parts.created_at_date else null end) as first_assignment_at, - min(case when conversation_parts.part_type = 'comment' and conversation_parts.author_type = 'admin' then conversation_parts.created_at_date else null end) as first_admin_response_at, - min(case when conversation_parts.part_type = 'open' then conversation_parts.created_at_date else null end) as first_reopen_at, - max(case when conversation_parts.part_type like '%assignment%' then conversation_parts.created_at_date else null end) as last_assignment_at, - max(case when conversation_parts.part_type = 'comment' and conversation_parts.author_type in ('lead','user') then conversation_parts.created_at_date else null end) as last_contact_reply_at, - max(case when conversation_parts.part_type = 'comment' and conversation_parts.author_type = 'admin' then conversation_parts.created_at_date else null end) as last_admin_response_at, - max(case when conversation_parts.part_type = 'open' then conversation_parts.created_at_date else null end) as last_reopen_at, - sum(case when conversation_parts.part_type like '%assignment%' then 1 else 0 end) as count_assignments, - sum(case when conversation_parts.part_type = 'open' then 1 else 0 end) as count_reopens - from latest_conversation - - left join conversation_parts - on latest_conversation.conversation_id = conversation_parts.conversation_id - - group by 1, 2 - -) - -select * -from final diff --git a/models/tmp/int_intercom__latest_company.sql b/models/tmp/int_intercom__latest_company.sql deleted file mode 100644 index 359a65c..0000000 --- a/models/tmp/int_intercom__latest_company.sql +++ /dev/null @@ -1,16 +0,0 @@ -with companies as ( - select * - from {{ ref('stg_intercom__companies') }} -), - ---Returns the most recent company record by creating a row number ordered by the updated_at_timestamp date, then filtering to only return the #1 row per company. -latest_company as ( - select - *, - row_number() over(partition by company_id order by updated_at_timestamp desc) as latest_company_index - from companies -) - -select * -from latest_company -where latest_company_index = 1 diff --git a/models/tmp/int_intercom__latest_contact.sql b/models/tmp/int_intercom__latest_contact.sql deleted file mode 100644 index 983dc06..0000000 --- a/models/tmp/int_intercom__latest_contact.sql +++ /dev/null @@ -1,16 +0,0 @@ -with contacts as ( - select * - from {{ ref('stg_intercom__contacts') }} -), - ---Returns the most recent contact record by creating a row number ordered by the updated_at_timestamp date, then filtering to only return the #1 row per contact. -latest_contact as ( - select - *, - row_number() over(partition by contact_id order by updated_at_timestamp desc) as latest_contact_index - from contacts -) - -select * -from latest_contact -where latest_contact_index = 1 diff --git a/models/tmp/int_intercom__latest_conversation.sql b/models/tmp/int_intercom__latest_conversation.sql deleted file mode 100644 index 82d8756..0000000 --- a/models/tmp/int_intercom__latest_conversation.sql +++ /dev/null @@ -1,16 +0,0 @@ -with conversations as ( - select * - from {{ ref('stg_intercom__conversations') }} -), - ---Returns the most recent conversation record by creating a row number ordered by the conversation_updated_at date, then filtering to only return the #1 row per conversation. -latest_conversation as ( - select - *, - row_number() over(partition by conversation_id order by updated_at desc) as latest_conversation_index - from conversations -) - -select * -from latest_conversation -where latest_conversation_index = 1 diff --git a/models/tmp/stg_facebook_ad_insights.sql b/models/tmp/stg_facebook_ad_insights.sql new file mode 100644 index 0000000..69b5aba --- /dev/null +++ b/models/tmp/stg_facebook_ad_insights.sql @@ -0,0 +1,16 @@ +with ad_insights as ( + select + ad_id, + ad_name, + adset_id, + objective, + spend, + clicks, + impressions, + account_name, + campaign_name, + created_time as created_at_timestamp, + _airbyte_ads_insights_hashid + from {{ var('ad_insights') }} +) + diff --git a/models/tmp/stg_facebook_ads_ads.sql b/models/tmp/stg_facebook_ads_ads.sql new file mode 100644 index 0000000..d58c304 --- /dev/null +++ b/models/tmp/stg_facebook_ads_ads.sql @@ -0,0 +1,44 @@ +with ads as ( + select + id as ad_id, + name as ad_name, + adset_id, + account_id, + campaign_id, + created_time as created_at_timestamp, + _airbyte_ads_hashid + from {{ var('ads') }} +), + +creatives as ( + select + id as creative_id, + _airbyte_ads_hashid + from {{ var('ad_creative') }} +), + +ad_creatives as ( + select + id as creative_id, + name + from {{ var('ad_creatives') }} +), + +ads as ( + select + ads.ad_id, + ads.ad_name, + ads.adset_id, + ads.account_id, + ad_insights.account_name + ads.campaign_id, + ad_insights.campaign_name, + ads.created_at_timestamp, + ad_insights.spend, + ad_insights.clicks, + ad_insights.impressions + from ads + left join {{ ref('stg_facebook_ads_ads_insights') }} ad_insights using(_airbyte_ads_hashid) + left join creatives using (_airbyte_ads_hashid) + left join ad_creatives using (creative_id) +), diff --git a/models/tmp/stg_facebook_ads_campaigns.sql b/models/tmp/stg_facebook_ads_campaigns.sql new file mode 100644 index 0000000..9face74 --- /dev/null +++ b/models/tmp/stg_facebook_ads_campaigns.sql @@ -0,0 +1,12 @@ +with campaigns as ( + select + id as campaign_id, + name as campaign_name, + objective, + account_id, + created_time as created_at_timestamp + from {{ var('campaigns') }} +) + +select * from campaigns + diff --git a/models/tmp/stg_intercom__admins.sql b/models/tmp/stg_intercom__admins.sql deleted file mode 100644 index 4d2b1a7..0000000 --- a/models/tmp/stg_intercom__admins.sql +++ /dev/null @@ -1,5 +0,0 @@ -select - cast(id as bigint) as admin_id, - type as admin_type, - * -from {{ var('admins') }} diff --git a/models/tmp/stg_intercom__companies.sql b/models/tmp/stg_intercom__companies.sql deleted file mode 100644 index 82c7871..0000000 --- a/models/tmp/stg_intercom__companies.sql +++ /dev/null @@ -1,12 +0,0 @@ -select - id as company_id, - name as company_name, - created_at as created_at_timestamp, - updated_at as updated_at_timestamp, - industry, - monthly_spend, - session_count, - user_count, - website, - _airbyte_companies_hashid -from {{ var('companies') }} diff --git a/models/tmp/stg_intercom__companies_plan.sql b/models/tmp/stg_intercom__companies_plan.sql deleted file mode 100644 index 2c3dde4..0000000 --- a/models/tmp/stg_intercom__companies_plan.sql +++ /dev/null @@ -1,5 +0,0 @@ -select - id as plan_id, - name as plan_name, - * -from {{ var('companies_plan') }} diff --git a/models/tmp/stg_intercom__contacts.sql b/models/tmp/stg_intercom__contacts.sql deleted file mode 100644 index 21f1621..0000000 --- a/models/tmp/stg_intercom__contacts.sql +++ /dev/null @@ -1,7 +0,0 @@ -select - id as contact_id, - created_at as created_at_timestamp, - updated_at as updated_at_timestamp, - last_seen_at as last_seen_at_timestamp, - * -from {{ var('contacts') }} diff --git a/models/tmp/stg_intercom__conversation_parts.sql b/models/tmp/stg_intercom__conversation_parts.sql deleted file mode 100644 index 0d92b9e..0000000 --- a/models/tmp/stg_intercom__conversation_parts.sql +++ /dev/null @@ -1,10 +0,0 @@ -select - id as conversation_part_id, - created_at as created_at_timestamp, - updated_at as updated_at_timestamp, - {{ dbt_date.from_unixtimestamp('created_at') }} as created_at_date, - {{ dbt_date.from_unixtimestamp('updated_at') }} as updated_at_date, - {{ fivetran_utils.json_parse(string="author", string_path=["id"]) }} as author_id, - {{ fivetran_utils.json_parse(string="author", string_path=["type"]) }} as author_type, - * -from {{ var('conversation_parts') }} diff --git a/models/tmp/stg_intercom__conversations.sql b/models/tmp/stg_intercom__conversations.sql deleted file mode 100644 index eb04453..0000000 --- a/models/tmp/stg_intercom__conversations.sql +++ /dev/null @@ -1,69 +0,0 @@ -with conversation_rating as ( - select - rating, - remark, - _airbyte_conversations_hashid - from {{ var('conversations_conversation_rating') }} -), - -conversations_sla_applied as ( - select - sla_name, - sla_status, - _airbyte_conversations_hashid - from {{ var('conversations_sla_applied') }} -), - -conversations_assignee as ( - select - id as assignee_id, - name as assignee_name, - type as assignee_type, - email as assignee_email, - _airbyte_conversations_hashid - from {{ var('conversations_assignee') }} -), - -conversations_statistics as ( - select - last_closed_by_id, - _airbyte_conversations_hashid - from {{ var('conversations_statistics') }} -), - -conversations as ( - select - id as conversation_id, - created_at as created_at_timestamp, - updated_at as updated_at_timestamp, - {{ dbt_date.from_unixtimestamp('created_at') }} as created_at_date, - {{ dbt_date.from_unixtimestamp('updated_at') }} as updated_at_date, - type as conversation_type, - title as conversation_title, - state as conversation_state, - read as is_read, - * - from {{ var('conversations') }} -), - -final as ( - select - conversations.*, - conversation_rating.rating as conversation_rating_value, - conversation_rating.remark as conversation_remark, - conversations_sla_applied.sla_name, - conversations_sla_applied.sla_status, - conversations_assignee.assignee_id, - conversations_assignee.assignee_name, - conversations_assignee.assignee_type, - conversations_assignee.assignee_email, - conversations_statistics.last_closed_by_id - from conversations - - left join conversation_rating using (_airbyte_conversations_hashid) - left join conversations_assignee using (_airbyte_conversations_hashid) - left join conversations_sla_applied using (_airbyte_conversations_hashid) - left join conversations_statistics using (_airbyte_conversations_hashid) -) - -select * from final