Skip to content

Commit

Permalink
fix other models
Browse files Browse the repository at this point in the history
  • Loading branch information
btkcodedev committed Aug 25, 2024
1 parent 7199d3f commit 67ad572
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 231 deletions.
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 connectors/source_twilio/models/fivetran_converter/address.sql
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 connectors/source_twilio/models/fivetran_converter/call.sql
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

0 comments on commit 67ad572

Please sign in to comment.