From 67ad572fe5a75221b57cf61af907ea0bfc2ff637 Mon Sep 17 00:00:00 2001 From: btkcodedev Date: Sun, 25 Aug 2024 22:52:25 +0530 Subject: [PATCH] fix other models --- .../fivetran_converter/account_history.sql | 74 ++-------- .../models/fivetran_converter/address.sql | 86 +++-------- .../models/fivetran_converter/call.sql | 138 ++++-------------- 3 files changed, 67 insertions(+), 231 deletions(-) diff --git a/connectors/source_twilio/models/fivetran_converter/account_history.sql b/connectors/source_twilio/models/fivetran_converter/account_history.sql index 202adc86..5b440382 100644 --- a/connectors/source_twilio/models/fivetran_converter/account_history.sql +++ b/connectors/source_twilio/models/fivetran_converter/account_history.sql @@ -1,58 +1,16 @@ -{% if target.type == "snowflake" %} - - WITH tmp AS ( - SELECT - {{ dbt.current_timestamp() }} AS _fivetran_synced, - cast(date_created AS {{ dbt.type_timestamp() }}) AS created_at, - friendly_name, - sid AS account_id, - owner_account_sid AS owner_account_id, - status, - type, - cast(date_updated AS {{ dbt.type_timestamp() }}) AS updated_at, - ROW_NUMBER() OVER (PARTITION BY sid ORDER BY date_updated DESC) = 1 AS is_most_recent_record - FROM - {{ source('source_twilio', 'accounts') }} - ) - SELECT * FROM tmp - WHERE account_id IS NOT NULL - -{% elif target.type == "bigquery" %} - - WITH tmp AS ( - SELECT - {{ dbt.current_timestamp() }} AS _fivetran_synced, - cast(date_created AS {{ dbt.type_timestamp() }}) AS created_at, - friendly_name, - sid AS account_id, - owner_account_sid AS owner_account_id, - status, - type, - cast(date_updated AS {{ dbt.type_timestamp() }}) AS updated_at, - ROW_NUMBER() OVER (PARTITION BY sid ORDER BY date_updated DESC) = 1 AS is_most_recent_record - FROM - {{ source('source_twilio', 'accounts') }} - ) - SELECT * FROM tmp - WHERE account_id IS NOT NULL - -{% elif target.type == "postgres" %} - - WITH tmp AS ( - SELECT - {{ dbt.current_timestamp() }} AS _fivetran_synced, - cast(date_created AS {{ dbt.type_timestamp() }}) AS created_at, - friendly_name, - sid AS account_id, - owner_account_sid AS owner_account_id, - status, - type, - cast(date_updated AS {{ dbt.type_timestamp() }}) AS updated_at, - ROW_NUMBER() OVER (PARTITION BY sid ORDER BY date_updated DESC) = 1 AS is_most_recent_record - FROM - {{ source('source_twilio', 'accounts') }} - ) - SELECT * FROM tmp - WHERE account_id IS NOT NULL - -{% endif %} +WITH tmp AS ( + SELECT + {{ dbt.current_timestamp() }} AS _fivetran_synced, + cast(date_created AS {{ dbt.type_timestamp() }}) AS created_at, + friendly_name, + sid AS account_id, + owner_account_sid AS owner_account_id, + status, + type, + cast(date_updated AS {{ dbt.type_timestamp() }}) AS updated_at, + ROW_NUMBER() OVER (PARTITION BY sid ORDER BY date_updated DESC) = 1 AS is_most_recent_record + FROM + {{ source('source_twilio', 'accounts') }} +) +SELECT * FROM tmp +WHERE account_id IS NOT NULL \ No newline at end of file diff --git a/connectors/source_twilio/models/fivetran_converter/address.sql b/connectors/source_twilio/models/fivetran_converter/address.sql index 28aefeb1..cda83b98 100644 --- a/connectors/source_twilio/models/fivetran_converter/address.sql +++ b/connectors/source_twilio/models/fivetran_converter/address.sql @@ -1,67 +1,19 @@ -{% if target.type == "snowflake" %} - - SELECT - {{ dbt.current_timestamp() }} AS _fivetran_synced, - account_sid AS account_id, - city, - cast(date_created AS {{ dbt.type_timestamp() }}) AS created_at, - customer_name, - emergency_enabled, - friendly_name, - cast(sid AS {{ dbt.type_string() }}) AS address_id, - iso_country, - postal_code, - region, - street, - cast(date_updated AS {{ dbt.type_timestamp() }}) AS updated_at, - validated, - verified - FROM - {{ source('source_twilio', 'addresses') }} - WHERE sid IS NOT NULL - -{% elif target.type == "bigquery" %} - - SELECT - {{ dbt.current_timestamp() }} AS _fivetran_synced, - account_sid AS account_id, - city, - cast(date_created AS {{ dbt.type_timestamp() }}) AS created_at, - customer_name, - emergency_enabled, - friendly_name, - cast(sid AS {{ dbt.type_string() }}) AS address_id, - iso_country, - postal_code, - region, - street, - cast(date_updated AS {{ dbt.type_timestamp() }}) AS updated_at, - validated, - verified - FROM - {{ source('source_twilio', 'addresses') }} - WHERE sid IS NOT NULL - -{% elif target.type == "postgres" %} - - SELECT - {{ dbt.current_timestamp() }} AS _fivetran_synced, - account_sid AS account_id, - city, - cast(date_created AS {{ dbt.type_timestamp() }}) AS created_at, - customer_name, - emergency_enabled, - friendly_name, - cast(sid AS {{ dbt.type_string() }}) AS address_id, - iso_country, - postal_code, - region, - street, - cast(date_updated AS {{ dbt.type_timestamp() }}) AS updated_at, - validated, - verified - FROM - {{ source('source_twilio', 'addresses') }} - WHERE sid IS NOT NULL - -{% endif %} +SELECT + {{ dbt.current_timestamp() }} AS _fivetran_synced, + account_sid AS account_id, + city, + cast(date_created AS {{ dbt.type_timestamp() }}) AS created_at, + customer_name, + emergency_enabled, + friendly_name, + cast(sid AS {{ dbt.type_string() }}) AS address_id, + iso_country, + postal_code, + region, + street, + cast(date_updated AS {{ dbt.type_timestamp() }}) AS updated_at, + validated, + verified +FROM + {{ source('source_twilio', 'addresses') }} +WHERE sid IS NOT NULL \ No newline at end of file diff --git a/connectors/source_twilio/models/fivetran_converter/call.sql b/connectors/source_twilio/models/fivetran_converter/call.sql index 36f6036b..12fea34c 100644 --- a/connectors/source_twilio/models/fivetran_converter/call.sql +++ b/connectors/source_twilio/models/fivetran_converter/call.sql @@ -1,106 +1,32 @@ -{% if target.type == "snowflake" %} - - WITH tmp AS ( - SELECT - {{ dbt.current_timestamp() }} AS _fivetran_synced, - account_sid AS account_id, - annotation, - answered_by, - caller_name, - cast(date_created AS {{ dbt.type_timestamp() }}) AS created_at, - direction, - cast({{ twilio_source.remove_non_numeric_chars('duration') }} AS {{ dbt.type_float() }}) AS duration, - cast(end_time AS {{ dbt.type_timestamp() }}) AS end_time, - forwarded_from, - "from" AS call_from, - from_formatted, - group_sid AS group_id, - sid AS call_id, - phone_number_sid AS outgoing_caller_id, - parent_call_sid AS parent_call_id, - cast({{ twilio_source.remove_non_numeric_chars('price') }} AS {{ dbt.type_float() }}) AS price, - price_unit, - cast({{ twilio_source.remove_non_numeric_chars('queue_time') }} AS {{ dbt.type_float() }}) AS queue_time, - cast(start_time AS {{ dbt.type_timestamp() }}) AS start_time, - status, - "to" AS call_to, - to_formatted, - trunk_sid AS trunk_id, - cast(date_updated AS {{ dbt.type_timestamp() }}) AS updated_at - FROM - {{ source('source_twilio', 'calls') }} - ) - SELECT * FROM tmp - WHERE call_id IS NOT NULL - -{% elif target.type == "bigquery" %} - - WITH tmp AS ( - SELECT - {{ dbt.current_timestamp() }} AS _fivetran_synced, - account_sid AS account_id, - annotation, - answered_by, - caller_name, - cast(date_created AS {{ dbt.type_timestamp() }}) AS created_at, - direction, - cast({{ twilio_source.remove_non_numeric_chars('duration') }} AS {{ dbt.type_float() }}) AS duration, - cast(end_time AS {{ dbt.type_timestamp() }}) AS end_time, - forwarded_from, - `from` AS call_from, - from_formatted, - group_sid AS group_id, - sid AS call_id, - phone_number_sid AS outgoing_caller_id, - parent_call_sid AS parent_call_id, - cast({{ twilio_source.remove_non_numeric_chars('price') }} AS {{ dbt.type_float() }}) AS price, - price_unit, - cast({{ twilio_source.remove_non_numeric_chars('queue_time') }} AS {{ dbt.type_float() }}) AS queue_time, - cast(start_time AS {{ dbt.type_timestamp() }}) AS start_time, - status, - `to` AS call_to, - to_formatted, - trunk_sid AS trunk_id, - cast(date_updated AS {{ dbt.type_timestamp() }}) AS updated_at - FROM - {{ source('source_twilio', 'calls') }} - ) - SELECT * FROM tmp - WHERE call_id IS NOT NULL - -{% elif target.type == "postgres" %} - - WITH tmp AS ( - SELECT - {{ dbt.current_timestamp() }} AS _fivetran_synced, - account_sid AS account_id, - annotation, - answered_by, - caller_name, - cast(date_created AS {{ dbt.type_timestamp() }}) AS created_at, - direction, - cast({{ twilio_source.remove_non_numeric_chars('duration') }} AS {{ dbt.type_float() }}) AS duration, - cast(end_time AS {{ dbt.type_timestamp() }}) AS end_time, - forwarded_from, - "from" AS call_from, - from_formatted, - group_sid AS group_id, - sid AS call_id, - phone_number_sid AS outgoing_caller_id, - parent_call_sid AS parent_call_id, - cast({{ twilio_source.remove_non_numeric_chars('price') }} AS {{ dbt.type_float() }}) AS price, - price_unit, - cast({{ twilio_source.remove_non_numeric_chars('queue_time') }} AS {{ dbt.type_float() }}) AS queue_time, - cast(start_time AS {{ dbt.type_timestamp() }}) AS start_time, - status, - "to" AS call_to, - to_formatted, - trunk_sid AS trunk_id, - cast(date_updated AS {{ dbt.type_timestamp() }}) AS updated_at - FROM - {{ source('source_twilio', 'calls') }} - ) - SELECT * FROM tmp - WHERE call_id IS NOT NULL - -{% endif %} +WITH tmp AS ( + SELECT + {{ dbt.current_timestamp() }} AS _fivetran_synced, + account_sid AS account_id, + annotation, + answered_by, + caller_name, + cast(date_created AS {{ dbt.type_timestamp() }}) AS created_at, + direction, + duration AS {{ dbt.type_float() }} AS duration, + cast(end_time AS {{ dbt.type_timestamp() }}) AS end_time, + forwarded_from, + "from" AS call_from, + from_formatted, + group_sid AS group_id, + sid AS call_id, + phone_number_sid AS outgoing_caller_id, + parent_call_sid AS parent_call_id, + price AS {{ dbt.type_float() }} AS price, + price_unit, + queue_time AS {{ dbt.type_float() }} AS queue_time, + cast(start_time AS {{ dbt.type_timestamp() }}) AS start_time, + status, + "to" AS call_to, + to_formatted, + trunk_sid AS trunk_id, + cast(date_updated AS {{ dbt.type_timestamp() }}) AS updated_at + FROM + {{ source('source_twilio', 'calls') }} +) +SELECT * FROM tmp +WHERE call_id IS NOT NULL