-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7199d3f
commit 67ad572
Showing
3 changed files
with
67 additions
and
231 deletions.
There are no files selected for viewing
74 changes: 16 additions & 58 deletions
74
connectors/source_twilio/models/fivetran_converter/account_history.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
86 changes: 19 additions & 67 deletions
86
connectors/source_twilio/models/fivetran_converter/address.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
138 changes: 32 additions & 106 deletions
138
connectors/source_twilio/models/fivetran_converter/call.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |