This SQL query combines data from three sources: campaign level reports, profile information, and campaign history. It filters for non-deleted profiles and the most recent campaign records. The query then joins these tables to create a summarized account-level report, aggregating metrics like cost, clicks, and impressions by account, date, and location. The result provides a daily overview of advertising performance for each Amazon account.
FilteringIntegrationAggregationwith report as (
select *
--use campaign report since account report not provided
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__campaign_level_report
),
account_info as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__profile
where _fivetran_deleted = False
),
campaigns as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__campaign_history
where is_most_recent_record = True
),
fields as (
select
report.source_relation,
report.date_day,
account_info.account_name,
account_info.account_id,
account_info.country_code,
account_info.profile_id,
sum(report.cost) as cost,
sum(report.clicks) as clicks,
sum(report.impressions) as impressions
--use campaign report since portfolio report not provided
from report
left join campaigns
on campaigns.campaign_id = report.campaign_id
and campaigns.source_relation = report.source_relation
left join account_info
on account_info.profile_id = campaigns.profile_id
and account_info.source_relation = campaigns.source_relation
group by 1,2,3,4,5,6
)
select *
from fields
Name | Type | Comment |
---|---|---|
date_day | date | None |
account_name | text | None |
account_id | text | None |
country_code | text | None |
profile_id | text | None |
cost | double precision | None |
clicks | bigint | None |
impressions | bigint | None |
This query integrates data from multiple Amazon Ads-related tables, including ad group reports, account information, portfolios, campaigns, and ad groups. It joins these tables to create a comprehensive view of ad performance metrics (cost, clicks, impressions) at the ad group level, including associated account, portfolio, and campaign details. The query filters for the most recent records in some tables and aggregates the performance metrics.
FilteringIntegrationAggregationwith report as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__ad_group_level_report
),
account_info as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__profile
where _fivetran_deleted = False
),
portfolios as (
select *
from TEST.PUBLIC_amazon_ads.int_amazon_ads__portfolio_history
),
campaigns as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__campaign_history
where is_most_recent_record = True
),
ad_groups as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__ad_group_history
where is_most_recent_record = True
),
fields as (
select
report.source_relation,
report.date_day,
account_info.account_name,
account_info.account_id,
account_info.country_code,
account_info.profile_id,
portfolios.portfolio_name,
portfolios.portfolio_id,
campaigns.campaign_name,
campaigns.campaign_id,
ad_groups.ad_group_name,
report.ad_group_id,
ad_groups.serving_status,
ad_groups.state,
ad_groups.default_bid,
report.campaign_bidding_strategy,
sum(report.cost) as cost,
sum(report.clicks) as clicks,
sum(report.impressions) as impressions
from report
left join ad_groups
on ad_groups.ad_group_id = report.ad_group_id
and ad_groups.source_relation = report.source_relation
left join campaigns
on campaigns.campaign_id = ad_groups.campaign_id
and campaigns.source_relation = ad_groups.source_relation
left join portfolios
on portfolios.portfolio_id = campaigns.portfolio_id
and portfolios.source_relation = campaigns.source_relation
left join account_info
on account_info.profile_id = campaigns.profile_id
and account_info.source_relation = campaigns.source_relation
group by 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
)
select *
from fields
Name | Type | Comment |
---|---|---|
date_day | date | None |
account_name | text | None |
account_id | text | None |
country_code | text | None |
profile_id | text | None |
portfolio_name | text | None |
portfolio_id | text | None |
campaign_name | text | None |
campaign_id | text | None |
ad_group_name | text | None |
ad_group_id | text | None |
serving_status | text | None |
state | text | None |
default_bid | double precision | None |
campaign_bidding_strategy | text | None |
cost | double precision | None |
clicks | bigint | None |
impressions | bigint | None |
This SQL query integrates data from multiple Amazon Ads-related tables to create a comprehensive ad report. It joins information from advertised product reports, account profiles, portfolios, campaigns, ad groups, and product ads. The query filters for the most recent records in some tables, aggregates cost, clicks, and impressions data, and combines various attributes such as account details, campaign information, and ad specifics into a single result set.
FilteringIntegrationAggregationwith report as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__advertised_product_report
),
account_info as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__profile
where _fivetran_deleted = False
),
portfolios as (
select *
from TEST.PUBLIC_amazon_ads.int_amazon_ads__portfolio_history
),
campaigns as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__campaign_history
where is_most_recent_record = True
),
ad_groups as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__ad_group_history
where is_most_recent_record = True
),
ads as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__product_ad_history
where is_most_recent_record = True
),
fields as (
select
report.source_relation,
report.date_day,
account_info.account_name,
account_info.account_id,
account_info.country_code,
account_info.profile_id,
portfolios.portfolio_name,
portfolios.portfolio_id,
campaigns.campaign_name,
report.campaign_id,
ad_groups.ad_group_name,
report.ad_group_id,
report.ad_id,
ads.serving_status,
ads.state,
report.advertised_asin,
report.advertised_sku,
report.campaign_budget_amount,
report.campaign_budget_currency_code,
report.campaign_budget_type,
sum(report.cost) as cost,
sum(report.clicks) as clicks,
sum(report.impressions) as impressions
from report
left join ads
on ads.ad_id = report.ad_id
and ads.source_relation = report.source_relation
left join ad_groups
on ad_groups.ad_group_id = report.ad_group_id
and ad_groups.source_relation = report.source_relation
left join campaigns
on campaigns.campaign_id = report.campaign_id
and campaigns.source_relation = report.source_relation
left join portfolios
on portfolios.portfolio_id = campaigns.portfolio_id
and portfolios.source_relation = campaigns.source_relation
left join account_info
on account_info.profile_id = campaigns.profile_id
and account_info.source_relation = campaigns.source_relation
group by 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
)
select *
from fields
Name | Type | Comment |
---|---|---|
date_day | date | None |
account_name | text | None |
account_id | text | None |
country_code | text | None |
profile_id | text | None |
portfolio_name | text | None |
portfolio_id | text | None |
campaign_name | text | None |
campaign_id | text | None |
ad_group_name | text | None |
ad_group_id | text | None |
ad_id | text | None |
serving_status | text | None |
state | text | None |
advertised_asin | integer | None |
advertised_sku | integer | None |
campaign_budget_amount | double precision | None |
campaign_budget_currency_code | text | None |
campaign_budget_type | text | None |
cost | double precision | None |
clicks | bigint | None |
impressions | bigint | None |
This SQL query integrates data from multiple Amazon Ads-related tables (campaign reports, account information, portfolios, and campaigns) to create a comprehensive campaign performance report. It joins these tables based on various ID fields and source relations, and then aggregates metrics such as cost, clicks, and impressions at the campaign level. The query also includes relevant information like account details, portfolio names, and campaign attributes.
IntegrationAggregationFilteringwith report as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__campaign_level_report
),
account_info as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__profile
where _fivetran_deleted = False
),
portfolios as (
select *
from TEST.PUBLIC_amazon_ads.int_amazon_ads__portfolio_history
),
campaigns as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__campaign_history
where is_most_recent_record = True
),
fields as (
select
report.source_relation,
report.date_day,
account_info.account_name,
account_info.account_id,
account_info.country_code,
account_info.profile_id,
portfolios.portfolio_name,
portfolios.portfolio_id,
campaigns.campaign_name,
report.campaign_id,
report.campaign_bidding_strategy,
report.campaign_budget_amount,
report.campaign_budget_currency_code,
report.campaign_budget_type,
sum(report.cost) as cost,
sum(report.clicks) as clicks,
sum(report.impressions) as impressions
from report
left join campaigns
on campaigns.campaign_id = report.campaign_id
and campaigns.source_relation = report.source_relation
left join portfolios
on portfolios.portfolio_id = campaigns.portfolio_id
and portfolios.source_relation = campaigns.source_relation
left join account_info
on account_info.profile_id = campaigns.profile_id
and account_info.source_relation = campaigns.source_relation
group by 1,2,3,4,5,6,7,8,9,10,11,12,13,14
)
select *
from fields
Name | Type | Comment |
---|---|---|
date_day | date | None |
account_name | text | None |
account_id | text | None |
country_code | text | None |
profile_id | text | None |
portfolio_name | text | None |
portfolio_id | text | None |
campaign_name | text | None |
campaign_id | text | None |
campaign_bidding_strategy | text | None |
campaign_budget_amount | double precision | None |
campaign_budget_currency_code | text | None |
campaign_budget_type | text | None |
cost | double precision | None |
clicks | bigint | None |
impressions | bigint | None |
This SQL query combines data from multiple Amazon Ads-related tables to create a comprehensive keyword report. It joins keyword performance data with account, portfolio, campaign, ad group, and keyword information. The query filters for the most recent records in some tables, aggregates cost, clicks, and impressions data, and provides a detailed view of keyword performance across different levels of the advertising structure.
FilteringIntegrationAggregationwith report as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__targeting_keyword_report
),
account_info as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__profile
where _fivetran_deleted = False
),
portfolios as (
select *
from TEST.PUBLIC_amazon_ads.int_amazon_ads__portfolio_history
),
campaigns as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__campaign_history
where is_most_recent_record = True
),
ad_groups as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__ad_group_history
where is_most_recent_record = True
),
keywords as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__keyword_history
where is_most_recent_record = True
),
fields as (
select
report.source_relation,
report.date_day,
account_info.account_name,
account_info.account_id,
account_info.country_code,
account_info.profile_id,
portfolios.portfolio_name,
portfolios.portfolio_id,
campaigns.campaign_name,
report.campaign_id,
ad_groups.ad_group_name,
report.ad_group_id,
report.keyword_id,
keywords.keyword_text,
keywords.serving_status,
keywords.state,
report.keyword_bid,
report.keyword_type,
report.match_type,
sum(report.cost) as cost,
sum(report.clicks) as clicks,
sum(report.impressions) as impressions
from report
left join keywords
on keywords.keyword_id = report.keyword_id
and keywords.source_relation = report.source_relation
left join ad_groups
on ad_groups.ad_group_id = report.ad_group_id
and ad_groups.source_relation = report.source_relation
left join campaigns
on campaigns.campaign_id = report.campaign_id
and campaigns.source_relation = report.source_relation
left join portfolios
on portfolios.portfolio_id = campaigns.portfolio_id
and portfolios.source_relation = campaigns.source_relation
left join account_info
on account_info.profile_id = campaigns.profile_id
and account_info.source_relation = campaigns.source_relation
group by 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
)
select *
from fields
Name | Type | Comment |
---|---|---|
date_day | date | None |
account_name | text | None |
account_id | text | None |
country_code | text | None |
profile_id | text | None |
portfolio_name | text | None |
portfolio_id | text | None |
campaign_name | text | None |
campaign_id | text | None |
ad_group_name | text | None |
ad_group_id | text | None |
keyword_id | text | None |
keyword_text | text | None |
serving_status | text | None |
state | text | None |
keyword_bid | double precision | None |
keyword_type | text | None |
match_type | text | None |
cost | double precision | None |
clicks | bigint | None |
impressions | bigint | None |
This SQL query integrates data from multiple Amazon Ads-related tables to create a comprehensive portfolio report. It joins information from campaign reports, account profiles, portfolio history, and campaign history. The query filters for the most recent records in portfolio and campaign history, and aggregates metrics like cost, clicks, and impressions at the portfolio level. The result provides a detailed view of portfolio performance including budget details, serving status, and associated account information.
FilteringIntegrationAggregationwith report as (
select *
--use campaign report since portfolio report not provided
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__campaign_level_report
),
account_info as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__profile
where _fivetran_deleted = False
),
portfolios as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__portfolio_history
where is_most_recent_record = True
),
campaigns as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__campaign_history
where is_most_recent_record = True
),
fields as (
select
report.source_relation,
report.date_day,
account_info.account_name,
account_info.account_id,
account_info.country_code,
account_info.profile_id,
portfolios.portfolio_name,
portfolios.portfolio_id,
portfolios.budget_amount,
portfolios.budget_currency_code,
portfolios.budget_start_date,
portfolios.budget_end_date,
portfolios.budget_policy,
portfolios.in_budget,
portfolios.serving_status,
portfolios.state,
sum(report.cost) as cost,
sum(report.clicks) as clicks,
sum(report.impressions) as impressions
--use campaign report since portfolio report not provided
from portfolios
left join campaigns
on campaigns.portfolio_id = portfolios.portfolio_id
and campaigns.source_relation = portfolios.source_relation
left join account_info
on account_info.profile_id = campaigns.profile_id
and account_info.source_relation = campaigns.source_relation
left join report
on report.campaign_id = campaigns.campaign_id
and report.source_relation = campaigns.source_relation
group by 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
)
select *
from fields
Name | Type | Comment |
---|---|---|
date_day | date | None |
account_name | text | None |
account_id | text | None |
country_code | text | None |
profile_id | text | None |
portfolio_name | text | None |
portfolio_id | text | None |
budget_amount | integer | None |
budget_currency_code | integer | None |
budget_start_date | integer | None |
budget_end_date | integer | None |
budget_policy | integer | None |
in_budget | boolean | None |
serving_status | text | None |
state | text | None |
cost | double precision | None |
clicks | bigint | None |
impressions | bigint | None |
This SQL query integrates data from multiple Amazon Ads-related tables to create a comprehensive search report. It joins information from search term reports, account profiles, portfolios, campaigns, ad groups, and keywords. The query filters for the most recent records in some tables, aggregates cost, clicks, and impressions, and provides a detailed view of search performance across various dimensions of the advertising structure.
FilteringIntegrationAggregationwith report as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__search_term_ad_keyword_report
),
account_info as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__profile
where _fivetran_deleted = False
),
portfolios as (
select *
from TEST.PUBLIC_amazon_ads.int_amazon_ads__portfolio_history
),
campaigns as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__campaign_history
where is_most_recent_record = True
),
ad_groups as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__ad_group_history
where is_most_recent_record = True
),
keywords as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__keyword_history
where is_most_recent_record = True
),
fields as (
select
report.source_relation,
report.date_day,
account_info.account_name,
account_info.account_id,
account_info.country_code,
account_info.profile_id,
portfolios.portfolio_name,
portfolios.portfolio_id,
campaigns.campaign_name,
report.campaign_id,
ad_groups.ad_group_name,
report.ad_group_id,
report.keyword_id,
keywords.keyword_text,
keywords.match_type,
keywords.serving_status,
keywords.state,
report.search_term,
report.targeting,
sum(report.cost) as cost,
sum(report.clicks) as clicks,
sum(report.impressions) as impressions
from report
left join keywords
on keywords.keyword_id = report.keyword_id
and keywords.source_relation = report.source_relation
left join ad_groups
on ad_groups.ad_group_id = report.ad_group_id
and ad_groups.source_relation = report.source_relation
left join campaigns
on campaigns.campaign_id = report.campaign_id
and campaigns.source_relation = report.source_relation
left join portfolios
on portfolios.portfolio_id = campaigns.portfolio_id
and portfolios.source_relation = campaigns.source_relation
left join account_info
on account_info.profile_id = campaigns.profile_id
and account_info.source_relation = campaigns.source_relation
group by 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19
)
select *
from fields
Name | Type | Comment |
---|---|---|
date_day | date | None |
account_name | text | None |
account_id | text | None |
country_code | text | None |
profile_id | text | None |
portfolio_name | text | None |
portfolio_id | text | None |
campaign_name | text | None |
campaign_id | text | None |
ad_group_name | text | None |
ad_group_id | text | None |
keyword_id | text | None |
keyword_text | text | None |
match_type | text | None |
serving_status | text | None |
state | text | None |
search_term | text | None |
targeting | text | None |
cost | double precision | None |
clicks | bigint | None |
impressions | bigint | None |
This SQL query selects all columns from the most recent records in the amazon_ads_source.stg_amazon_ads__portfolio_history table. It filters the data to include only the rows where 'is_most_recent_record' is True, effectively retrieving the latest snapshot of portfolio data.
Filteringwith portfolios as (
select
*
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__portfolio_history
where is_most_recent_record = True
)
select *
from portfolios
Name | Type | Comment |
---|---|---|
portfolio_id | text | None |
budget_amount | integer | None |
budget_currency_code | integer | None |
budget_end_date | integer | None |
budget_policy | integer | None |
budget_start_date | integer | None |
creation_date | text | None |
in_budget | boolean | None |
last_updated_date | text | None |
portfolio_name | text | None |
profile_id | text | None |
serving_status | text | None |
state | text | None |
is_most_recent_record | boolean | None |
This SQL query stages data from an Amazon Ads source table, focusing on ad group history. It casts various fields to specific data types, renames some columns, and adds a source relation field. The query then selects and transforms these fields, including adding a flag to identify the most recent record for each ad group. This staging process prepares the data for further use in the data pipeline.
CleaningDeduplicationOtherwith base as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__ad_group_history_tmp
),
fields as (
select
cast(null as integer) as
campaign_id
,
cast(null as timestamp) as
creation_date
,
cast(null as float) as
default_bid
,
cast(null as TEXT) as
id
,
cast(null as timestamp) as
last_updated_date
,
cast(null as TEXT) as
name
,
cast(null as TEXT) as
serving_status
,
cast(null as TEXT) as
state
, cast('' as TEXT) as source_relation
from base
),
final as (
select
source_relation,
cast(id as TEXT) as ad_group_id,
cast(campaign_id as TEXT) as campaign_id,
creation_date,
default_bid,
last_updated_date,
name as ad_group_name,
serving_status,
state,
row_number() over (partition by source_relation, id order by last_updated_date desc) = 1 as is_most_recent_record
from fields
)
select *
from final
Name | Type | Comment |
---|---|---|
ad_group_id | text | None |
campaign_id | text | None |
creation_date | text | None |
default_bid | double precision | None |
last_updated_date | text | None |
ad_group_name | text | None |
serving_status | text | None |
state | text | None |
is_most_recent_record | boolean | None |
This SQL query creates an empty result set with a single column named '_dbt_source_relation' of TEXT data type. It's likely used as a placeholder or template for further development or testing purposes.
Other
select
cast(null as TEXT) as _dbt_source_relation
limit 0
Name | Type | Comment |
---|---|---|
id | integer | None |
last_updated_date | text | None |
_fivetran_synced | timestamp without time zone | None |
campaign_id | integer | None |
creation_date | text | None |
default_bid | double precision | None |
name | text | None |
serving_status | text | None |
state | text | None |
This SQL query performs data type casting and column renaming for a staging table. It selects data from a temporary table, casts columns to specific data types (integer, text, float, date), and renames the 'date' column to 'date_day'. The query also adds a 'source_relation' column and casts the 'ad_group_id' to TEXT in the final selection.
CleaningOtherwith base as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__ad_group_level_report_tmp
),
fields as (
select
cast(null as integer) as
ad_group_id
,
cast(null as TEXT) as
campaign_bidding_strategy
,
cast(null as integer) as
clicks
,
cast(null as float) as
cost
,
cast(null as date) as
date
,
cast(null as integer) as
impressions
, cast('' as TEXT) as source_relation
from base
),
final as (
select
source_relation,
cast(ad_group_id as TEXT) as ad_group_id,
campaign_bidding_strategy,
clicks,
cost,
date as date_day,
impressions
from fields
)
select *
from final
Name | Type | Comment |
---|---|---|
ad_group_id | text | None |
campaign_bidding_strategy | text | None |
clicks | integer | None |
cost | double precision | None |
date_day | date | None |
impressions | integer | None |
This SQL query creates an empty result set with a single column named '_dbt_source_relation' of TEXT data type. The query doesn't select any actual data; it's used to define the structure of the result set without populating it with any rows.
Other
select
cast(null as TEXT) as _dbt_source_relation
limit 0
Name | Type | Comment |
---|---|---|
ad_group_id | integer | None |
date | date | None |
_fivetran_synced | timestamp without time zone | None |
campaign_bidding_strategy | text | None |
clicks | integer | None |
cost | double precision | None |
impressions | integer | None |
This SQL query performs data cleaning and type casting operations on the 'stg_amazon_ads__advertised_product_report_tmp' table. It selects all columns from the base table, explicitly casts them to specific data types, and renames some columns. The query also adds a 'source_relation' column and performs final type casting on certain fields before selecting all columns in the final output.
Cleaningwith base as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__advertised_product_report_tmp
),
fields as (
select
cast(null as integer) as
ad_group_id
,
cast(null as integer) as
ad_id
,
cast(null as TEXT) as
advertised_asin
,
cast(null as TEXT) as
advertised_sku
,
cast(null as float) as
campaign_budget_amount
,
cast(null as TEXT) as
campaign_budget_currency_code
,
cast(null as TEXT) as
campaign_budget_type
,
cast(null as integer) as
campaign_id
,
cast(null as integer) as
clicks
,
cast(null as float) as
cost
,
cast(null as date) as
date
,
cast(null as integer) as
impressions
, cast('' as TEXT) as source_relation
from base
),
final as (
select
source_relation,
cast(ad_id as TEXT) as ad_id,
cast(ad_group_id as TEXT) as ad_group_id,
advertised_asin,
advertised_sku,
campaign_budget_amount,
campaign_budget_currency_code,
campaign_budget_type,
cast(campaign_id as TEXT) as campaign_id,
clicks,
cost,
date as date_day,
impressions
from fields
)
select *
from final
Name | Type | Comment |
---|---|---|
ad_id | text | None |
ad_group_id | text | None |
advertised_asin | integer | None |
advertised_sku | integer | None |
campaign_budget_amount | double precision | None |
campaign_budget_currency_code | text | None |
campaign_budget_type | text | None |
campaign_id | text | None |
clicks | integer | None |
cost | double precision | None |
date_day | date | None |
impressions | integer | None |
This SQL query creates an empty result set with a single column named '_dbt_source_relation' of type TEXT. It doesn't perform any actual data manipulation or retrieval from the mentioned model. The query is likely used as a placeholder or template for further development.
Other
select
cast(null as TEXT) as _dbt_source_relation
limit 0
Name | Type | Comment |
---|---|---|
ad_group_id | integer | None |
ad_id | integer | None |
campaign_id | integer | None |
date | date | None |
_fivetran_synced | timestamp without time zone | None |
campaign_budget_amount | double precision | None |
campaign_budget_currency_code | text | None |
campaign_budget_type | text | None |
clicks | integer | None |
cost | double precision | None |
impressions | integer | None |
advertised_asin | integer | None |
advertised_sku | integer | None |
This SQL query stages data from an Amazon Ads campaign history source. It casts various fields to specific data types, renames some columns, and adds a source relation column. The query also includes logic to identify the most recent record for each campaign using a window function. The final output includes all transformed columns along with a boolean flag indicating if each record is the most recent for that campaign.
CleaningDeduplicationOtherwith base as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__campaign_history_tmp
),
fields as (
select
cast(null as TEXT) as
bidding_strategy
,
cast(null as timestamp) as
creation_date
,
cast(null as date) as
end_date
,
cast(null as TEXT) as
id
,
cast(null as timestamp) as
last_updated_date
,
cast(null as TEXT) as
name
,
cast(null as integer) as
portfolio_id
,
cast(null as integer) as
profile_id
,
cast(null as TEXT) as
serving_status
,
cast(null as date) as
start_date
,
cast(null as TEXT) as
state
,
cast(null as TEXT) as
targeting_type
,
cast(null as float) as
budget
,
cast(null as TEXT) as
budget_type
,
cast(null as float) as
effective_budget
, cast('' as TEXT) as source_relation
from base
),
final as (
select
source_relation,
cast(id as TEXT) as campaign_id,
last_updated_date,
bidding_strategy,
creation_date,
end_date,
name as campaign_name,
cast(portfolio_id as TEXT) as portfolio_id,
cast(profile_id as TEXT) as profile_id,
serving_status,
start_date,
state,
targeting_type,
budget,
budget_type,
effective_budget,
row_number() over (partition by source_relation, id order by last_updated_date desc) = 1 as is_most_recent_record
from fields
)
select *
from final
Name | Type | Comment |
---|---|---|
campaign_id | text | None |
last_updated_date | text | None |
bidding_strategy | text | None |
creation_date | text | None |
end_date | integer | None |
campaign_name | text | None |
portfolio_id | text | None |
profile_id | text | None |
serving_status | text | None |
start_date | date | None |
state | text | None |
targeting_type | text | None |
budget | integer | None |
budget_type | text | None |
effective_budget | integer | None |
is_most_recent_record | boolean | None |
This SQL query creates an empty result set with a single column named '_dbt_source_relation' of TEXT data type. It doesn't retrieve any actual data from the 'model.amazon_ads_source.stg_amazon_ads__campaign_history_tmp' model, as it limits the results to 0 rows. This query appears to be a placeholder or template for generating a schema without any data.
Other
select
cast(null as TEXT) as _dbt_source_relation
limit 0
Name | Type | Comment |
---|---|---|
id | integer | None |
last_updated_date | text | None |
_fivetran_synced | timestamp without time zone | None |
bidding_strategy | text | None |
creation_date | text | None |
budget | integer | None |
end_date | integer | None |
name | text | None |
portfolio_id | integer | None |
profile_id | integer | None |
serving_status | text | None |
start_date | date | None |
state | text | None |
targeting_type | text | None |
budget_type | text | None |
effective_budget | integer | None |
This SQL query stages data from a temporary table, casts various fields to specific data types, and prepares a final selection of columns for the Amazon Ads campaign-level report. It primarily focuses on cleaning and standardizing the data structure.
CleaningOtherwith base as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__campaign_level_report_tmp
),
fields as (
select
cast(null as TEXT) as
campaign_applicable_budget_rule_id
,
cast(null as TEXT) as
campaign_applicable_budget_rule_name
,
cast(null as TEXT) as
campaign_bidding_strategy
,
cast(null as float) as
campaign_budget_amount
,
cast(null as TEXT) as
campaign_budget_currency_code
,
cast(null as TEXT) as
campaign_budget_type
,
cast(null as integer) as
campaign_id
,
cast(null as float) as
campaign_rule_based_budget_amount
,
cast(null as integer) as
clicks
,
cast(null as float) as
cost
,
cast(null as date) as
date
,
cast(null as integer) as
impressions
, cast('' as TEXT) as source_relation
from base
),
final as (
select
source_relation,
campaign_applicable_budget_rule_id,
campaign_applicable_budget_rule_name,
campaign_bidding_strategy,
campaign_budget_amount,
campaign_budget_currency_code,
campaign_budget_type,
cast(campaign_id as TEXT) as campaign_id,
campaign_rule_based_budget_amount,
clicks,
cost,
date as date_day,
impressions
from fields
)
select *
from final
Name | Type | Comment |
---|---|---|
campaign_applicable_budget_rule_id | integer | None |
campaign_applicable_budget_rule_name | integer | None |
campaign_bidding_strategy | text | None |
campaign_budget_amount | double precision | None |
campaign_budget_currency_code | text | None |
campaign_budget_type | text | None |
campaign_id | text | None |
campaign_rule_based_budget_amount | integer | None |
clicks | integer | None |
cost | double precision | None |
date_day | date | None |
impressions | integer | None |
This SQL query creates an empty result set with a single column named '_dbt_source_relation' of TEXT data type. It's likely used as a placeholder or template for further development or testing purposes.
Other
select
cast(null as TEXT) as _dbt_source_relation
limit 0
Name | Type | Comment |
---|---|---|
campaign_id | integer | None |
date | date | None |
_fivetran_synced | timestamp without time zone | None |
campaign_applicable_budget_rule_id | integer | None |
campaign_applicable_budget_rule_name | integer | None |
campaign_bidding_strategy | text | None |
campaign_budget_amount | double precision | None |
campaign_budget_currency_code | text | None |
campaign_budget_type | text | None |
clicks | integer | None |
cost | double precision | None |
impressions | integer | None |
campaign_rule_based_budget_amount | integer | None |
This SQL query processes data from a staging table for Amazon Ads keyword history. It casts various fields to specific data types, renames some columns, and adds a source relation field. The query also includes a window function to identify the most recent record for each keyword across different source relations. Finally, it selects all fields from the processed data.
CleaningDeduplicationOtherwith base as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__keyword_history_tmp
),
fields as (
select
cast(null as integer) as
ad_group_id
,
cast(null as float) as
bid
,
cast(null as integer) as
campaign_id
,
cast(null as timestamp) as
creation_date
,
cast(null as TEXT) as
id
,
cast(null as TEXT) as
keyword_text
,
cast(null as timestamp) as
last_updated_date
,
cast(null as TEXT) as
match_type
,
cast(null as TEXT) as
native_language_keyword
,
cast(null as TEXT) as
serving_status
,
cast(null as TEXT) as
state
,
cast(null as TEXT) as
native_language_locale
, cast('' as TEXT) as source_relation
from base
),
final as (
select
source_relation,
cast(id as TEXT) as keyword_id,
cast(ad_group_id as TEXT) as ad_group_id,
bid,
cast(campaign_id as TEXT) as campaign_id,
creation_date,
keyword_text,
last_updated_date,
match_type,
native_language_keyword,
serving_status,
state,
native_language_locale,
row_number() over (partition by source_relation, id order by last_updated_date desc) = 1 as is_most_recent_record
from fields
)
select *
from final
Name | Type | Comment |
---|---|---|
keyword_id | text | None |
ad_group_id | text | None |
bid | double precision | None |
campaign_id | text | None |
creation_date | text | None |
keyword_text | text | None |
last_updated_date | text | None |
match_type | text | None |
native_language_keyword | integer | None |
serving_status | text | None |
state | text | None |
native_language_locale | integer | None |
is_most_recent_record | boolean | None |
This SQL query creates an empty result set with a single column named '_dbt_source_relation' of TEXT data type. It doesn't perform any actual data manipulation or retrieval from the 'model.amazon_ads_source.stg_amazon_ads__keyword_history_tmp' model. The query is likely used as a placeholder or for testing purposes.
Other
select
cast(null as TEXT) as _dbt_source_relation
limit 0
Name | Type | Comment |
---|---|---|
id | integer | None |
last_updated_date | text | None |
_fivetran_synced | timestamp without time zone | None |
ad_group_id | integer | None |
bid | double precision | None |
campaign_id | integer | None |
creation_date | text | None |
keyword_text | text | None |
match_type | text | None |
native_language_keyword | integer | None |
serving_status | text | None |
state | text | None |
native_language_locale | integer | None |
This SQL query stages data from a temporary table, casts columns to specific data types, renames some columns, and adds a source_relation column. It then creates a final table with transformed columns, including a new column to identify the most recent record for each portfolio. The query focuses on preparing Amazon Ads portfolio history data for further analysis or integration.
CleaningDeduplicationOtherwith base as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__portfolio_history_tmp
),
fields as (
select
cast(null as float) as
budget_amount
,
cast(null as TEXT) as
budget_currency_code
,
cast(null as date) as
budget_end_date
,
cast(null as TEXT) as
budget_policy
,
cast(null as date) as
budget_start_date
,
cast(null as timestamp) as
creation_date
,
cast(null as integer) as
id
,
cast(null as boolean) as
in_budget
,
cast(null as timestamp) as
last_updated_date
,
cast(null as TEXT) as
name
,
cast(null as integer) as
profile_id
,
cast(null as TEXT) as
serving_status
,
cast(null as TEXT) as
state
, cast('' as TEXT) as source_relation
from base
),
final as (
select
source_relation,
cast(id as TEXT) as portfolio_id,
budget_amount,
budget_currency_code,
budget_end_date,
budget_policy,
budget_start_date,
creation_date,
in_budget,
last_updated_date,
name as portfolio_name,
cast(profile_id as TEXT) as profile_id,
serving_status,
state,
row_number() over (partition by source_relation, id order by last_updated_date desc) = 1 as is_most_recent_record
from fields
)
select *
from final
Name | Type | Comment |
---|---|---|
portfolio_id | text | None |
budget_amount | integer | None |
budget_currency_code | integer | None |
budget_end_date | integer | None |
budget_policy | integer | None |
budget_start_date | integer | None |
creation_date | text | None |
in_budget | boolean | None |
last_updated_date | text | None |
portfolio_name | text | None |
profile_id | text | None |
serving_status | text | None |
state | text | None |
is_most_recent_record | boolean | None |
This SQL query creates an empty result set with a single column named '_dbt_source_relation' of TEXT data type. It's likely used as a placeholder or template for further operations in a dbt (data build tool) project, specifically for staging Amazon Ads portfolio history data.
Other
select
cast(null as TEXT) as _dbt_source_relation
limit 0
Name | Type | Comment |
---|---|---|
id | integer | None |
last_updated_date | text | None |
_fivetran_synced | timestamp without time zone | None |
budget_amount | integer | None |
budget_currency_code | integer | None |
budget_end_date | integer | None |
budget_policy | integer | None |
budget_start_date | integer | None |
creation_date | text | None |
in_budget | boolean | None |
name | text | None |
profile_id | integer | None |
serving_status | text | None |
state | text | None |
This SQL query processes data from a staging table for Amazon Ads product ad history. It casts various fields to specific data types, renames some columns, adds a source_relation column, and creates a flag for the most recent record for each ad ID. The query also structures the data into a final format with selected columns.
CleaningDeduplicationOtherwith base as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__product_ad_history_tmp
),
fields as (
select
cast(null as integer) as
ad_group_id
,
cast(null as TEXT) as
asin
,
cast(null as integer) as
campaign_id
,
cast(null as timestamp) as
creation_date
,
cast(null as TEXT) as
id
,
cast(null as timestamp) as
last_updated_date
,
cast(null as TEXT) as
serving_status
,
cast(null as TEXT) as
sku
,
cast(null as TEXT) as
state
, cast('' as TEXT) as source_relation
from base
),
final as (
select
source_relation,
cast(id as TEXT) as ad_id,
cast(ad_group_id as TEXT) as ad_group_id,
asin,
cast(campaign_id as TEXT) as campaign_id,
creation_date,
last_updated_date,
serving_status,
sku,
state,
row_number() over (partition by source_relation, id order by last_updated_date desc) = 1 as is_most_recent_record
from fields
)
select *
from final
Name | Type | Comment |
---|---|---|
ad_id | text | None |
ad_group_id | text | None |
asin | text | None |
campaign_id | text | None |
creation_date | text | None |
last_updated_date | text | None |
serving_status | text | None |
sku | integer | None |
state | text | None |
is_most_recent_record | boolean | None |
This SQL query creates an empty result set with a single column named '_dbt_source_relation' of TEXT data type. It doesn't perform any actual data manipulation or retrieval from the 'model.amazon_ads_source.stg_amazon_ads__product_ad_history_tmp' model. The query is likely used as a placeholder or template for future development.
Other
select
cast(null as TEXT) as _dbt_source_relation
limit 0
Name | Type | Comment |
---|---|---|
id | integer | None |
last_updated_date | text | None |
_fivetran_synced | timestamp without time zone | None |
ad_group_id | integer | None |
asin | text | None |
campaign_id | integer | None |
creation_date | text | None |
serving_status | text | None |
sku | integer | None |
state | text | None |
This SQL query stages data from a temporary table, casts all fields to specific data types (mostly to null or empty values), and then formats the final output by renaming some columns and casting certain fields. It appears to be preparing a standardized structure for Amazon Ads profile data.
CleaningOtherwith base as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__profile_tmp
),
fields as (
select
cast(null as integer) as
id
,
cast(null as TEXT) as
account_id
,
cast(null as TEXT) as
account_marketplace_string_id
,
cast(null as TEXT) as
account_name
,
cast(null as TEXT) as
account_sub_type
,
cast(null as TEXT) as
account_type
,
cast(null as boolean) as
account_valid_payment_method
,
cast(null as TEXT) as
country_code
,
cast(null as TEXT) as
currency_code
,
cast(null as integer) as
daily_budget
,
cast(null as TEXT) as
timezone
,
cast(null as boolean) as
_fivetran_deleted
, cast('' as TEXT) as source_relation
from base
),
final as (
select
source_relation,
cast(id as TEXT) as profile_id,
cast(account_id as TEXT) as account_id,
account_marketplace_string_id,
account_name,
account_sub_type,
account_type,
account_valid_payment_method,
country_code,
currency_code,
daily_budget,
timezone,
_fivetran_deleted
from fields
)
select *
from final
Name | Type | Comment |
---|---|---|
profile_id | text | None |
account_id | text | None |
account_marketplace_string_id | text | None |
account_name | text | None |
account_sub_type | integer | None |
account_type | text | None |
account_valid_payment_method | boolean | None |
country_code | text | None |
currency_code | text | None |
daily_budget | integer | None |
timezone | text | None |
_fivetran_deleted | boolean | None |
This SQL query creates an empty result set with a single column named '_dbt_source_relation' of TEXT data type. It's likely used as a placeholder or template for further development or testing purposes.
Other
select
cast(null as TEXT) as _dbt_source_relation
limit 0
Name | Type | Comment |
---|---|---|
id | integer | None |
_fivetran_deleted | boolean | None |
_fivetran_synced | timestamp without time zone | None |
account_id | text | None |
account_marketplace_string_id | text | None |
account_name | text | None |
account_sub_type | integer | None |
account_type | text | None |
account_valid_payment_method | boolean | None |
country_code | text | None |
currency_code | text | None |
daily_budget | integer | None |
timezone | text | None |
This SQL query performs data type casting and column renaming on a staging table for Amazon Ads search term and keyword report data. It creates a CTE structure to organize the transformations, casting various columns to appropriate data types (integer, float, text, date) and renaming some columns. The query also adds a 'source_relation' column and adjusts some column names in the final select statement.
CleaningOtherwith base as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__search_term_ad_keyword_report_tmp
),
fields as (
select
cast(null as integer) as
ad_group_id
,
cast(null as TEXT) as
ad_keyword_status
,
cast(null as float) as
campaign_budget_amount
,
cast(null as TEXT) as
campaign_budget_currency_code
,
cast(null as TEXT) as
campaign_budget_type
,
cast(null as integer) as
campaign_id
,
cast(null as integer) as
clicks
,
cast(null as float) as
cost
,
cast(null as date) as
date
,
cast(null as integer) as
impressions
,
cast(null as float) as
keyword_bid
,
cast(null as integer) as
keyword_id
,
cast(null as TEXT) as
search_term
,
cast(null as TEXT) as
targeting
, cast('' as TEXT) as source_relation
from base
),
final as (
select
source_relation,
cast(ad_group_id as TEXT) as ad_group_id,
ad_keyword_status,
campaign_budget_amount,
campaign_budget_currency_code,
campaign_budget_type,
cast(campaign_id as TEXT) as campaign_id,
clicks,
cost,
date as date_day,
impressions,
keyword_bid,
cast(keyword_id as TEXT) as keyword_id,
search_term,
targeting
from fields
)
select *
from final
Name | Type | Comment |
---|---|---|
ad_group_id | text | None |
ad_keyword_status | text | None |
campaign_budget_amount | double precision | None |
campaign_budget_currency_code | text | None |
campaign_budget_type | text | None |
campaign_id | text | None |
clicks | integer | None |
cost | double precision | None |
date_day | date | None |
impressions | integer | None |
keyword_bid | double precision | None |
keyword_id | text | None |
search_term | text | None |
targeting | text | None |
This SQL query creates an empty result set with a single column named '_dbt_source_relation' of type TEXT. The query doesn't actually select any data from a table; instead, it creates a dummy result with zero rows. This type of query is often used as a placeholder or template in data modeling tools like dbt.
Other
select
cast(null as TEXT) as _dbt_source_relation
limit 0
Name | Type | Comment |
---|---|---|
ad_group_id | integer | None |
campaign_id | integer | None |
date | date | None |
keyword_id | integer | None |
_fivetran_synced | timestamp without time zone | None |
campaign_budget_amount | double precision | None |
campaign_budget_currency_code | text | None |
campaign_budget_type | text | None |
clicks | integer | None |
cost | double precision | None |
impressions | integer | None |
keyword_bid | double precision | None |
search_term | text | None |
targeting | text | None |
This SQL query performs data type casting and column renaming on a staging table for Amazon Ads targeting keyword reports. It creates a CTE structure to first select all columns from the source table, then defines data types for each column using CAST statements, and finally selects and renames some columns in the final output. The query also adds a 'source_relation' column to track the data source.
CleaningOtherwith base as (
select *
from TEST.PUBLIC_amazon_ads_source.stg_amazon_ads__targeting_keyword_report_tmp
),
fields as (
select
cast(null as integer) as
ad_group_id
,
cast(null as TEXT) as
ad_keyword_status
,
cast(null as float) as
campaign_budget_amount
,
cast(null as TEXT) as
campaign_budget_currency_code
,
cast(null as TEXT) as
campaign_budget_type
,
cast(null as integer) as
campaign_id
,
cast(null as integer) as
clicks
,
cast(null as float) as
cost
,
cast(null as date) as
date
,
cast(null as integer) as
impressions
,
cast(null as float) as
keyword_bid
,
cast(null as integer) as
keyword_id
,
cast(null as TEXT) as
keyword_type
,
cast(null as TEXT) as
match_type
,
cast(null as TEXT) as
targeting
, cast('' as TEXT) as source_relation
from base
),
final as (
select
source_relation,
cast(ad_group_id as TEXT) as ad_group_id,
ad_keyword_status,
campaign_budget_amount,
campaign_budget_currency_code,
campaign_budget_type,
cast(campaign_id as TEXT) as campaign_id,
clicks,
cost,
date as date_day,
impressions,
keyword_bid,
cast(keyword_id as TEXT) as keyword_id,
keyword_type,
match_type,
targeting
from fields
)
select *
from final
Name | Type | Comment |
---|---|---|
ad_group_id | text | None |
ad_keyword_status | text | None |
campaign_budget_amount | double precision | None |
campaign_budget_currency_code | text | None |
campaign_budget_type | text | None |
campaign_id | text | None |
clicks | integer | None |
cost | double precision | None |
date_day | date | None |
impressions | integer | None |
keyword_bid | double precision | None |
keyword_id | text | None |
keyword_type | text | None |
match_type | text | None |
targeting | text | None |
This SQL query creates an empty result set with a single column named '_dbt_source_relation' of type TEXT. It's likely used as a placeholder or template for further development, as it doesn't retrieve any actual data.
Other
select
cast(null as TEXT) as _dbt_source_relation
limit 0
Name | Type | Comment |
---|---|---|
ad_group_id | integer | None |
campaign_id | integer | None |
date | date | None |
keyword_id | integer | None |
_fivetran_synced | timestamp without time zone | None |
ad_keyword_status | text | None |
campaign_budget_amount | double precision | None |
campaign_budget_currency_code | text | None |
campaign_budget_type | text | None |
clicks | integer | None |
cost | double precision | None |
impressions | integer | None |
keyword_bid | double precision | None |
keyword_type | text | None |
match_type | text | None |
targeting | text | None |