From 393dfb38d03b74aebfd8faad0d0e423e280c57f7 Mon Sep 17 00:00:00 2001 From: shantanu73 Date: Thu, 2 Nov 2023 10:11:25 +0000 Subject: [PATCH] Changes: 1) Modified schema for video_ads stream. 2) Added transform logic to add ad_context fields to root level. --- tap_linkedin_ads/schemas/video_ads.json | 24 ++++++++++++++++++++++++ tap_linkedin_ads/transform.py | 13 +++++++++++++ 2 files changed, 37 insertions(+) diff --git a/tap_linkedin_ads/schemas/video_ads.json b/tap_linkedin_ads/schemas/video_ads.json index de8ca8b..158ba95 100644 --- a/tap_linkedin_ads/schemas/video_ads.json +++ b/tap_linkedin_ads/schemas/video_ads.json @@ -11,6 +11,30 @@ "integer" ] }, + "status": { + "type": [ + "null", + "string" + ] + }, + "name": { + "type": [ + "null", + "string" + ] + }, + "type": { + "type": [ + "null", + "string" + ] + }, + "account": { + "type": [ + "null", + "string" + ] + }, "ad_context": { "type": [ "null", diff --git a/tap_linkedin_ads/transform.py b/tap_linkedin_ads/transform.py index b8db09e..2db7d3b 100644 --- a/tap_linkedin_ads/transform.py +++ b/tap_linkedin_ads/transform.py @@ -254,6 +254,18 @@ def transform_creatives(data_dict): return new_dict +# Copy ad context fields to root level +def transform_ad_context_fields(data_dict): + if 'ad_context' in data_dict: + if 'dsc_status' in data_dict['ad_context']: + data_dict['status'] = data_dict['ad_context']['dsc_status'] + if 'dsc_name' in data_dict['ad_context']: + data_dict['name'] = data_dict['ad_context']['dsc_name'] + if 'dsc_ad_type' in data_dict['ad_context']: + data_dict['type'] = data_dict['ad_context']['dsc_ad_type'] + if 'dsc_ad_account' in data_dict['ad_context']: + data_dict['account'] = data_dict['ad_context']['dsc_ad_account'] + return data_dict # Create ID field for each URN def transform_urn(data_dict): @@ -295,6 +307,7 @@ def transform_data(data_dict, stream_name): this_dict = transform_campaigns(this_dict) elif stream_name == 'creatives': this_dict = transform_creatives(this_dict) + this_dict = transform_ad_context_fields(this_dict) this_dict = transform_urn(this_dict) new_dict['elements'][i] = this_dict