From 7f766fbae3c25e72aa4bb274d1ff4c23333b0989 Mon Sep 17 00:00:00 2001 From: Jamie Rodriguez <65564846+fivetran-jamie@users.noreply.github.com> Date: Wed, 26 Apr 2023 15:20:56 -0700 Subject: [PATCH 01/10] redshift working? --- integration_tests/dbt_project.yml | 2 +- .../int_iterable__list_user_history.sql | 2 +- .../int_iterable__list_user_unnest.sql | 101 +++++++++++++----- 3 files changed, 77 insertions(+), 28 deletions(-) diff --git a/integration_tests/dbt_project.yml b/integration_tests/dbt_project.yml index 161ac07..472b53f 100644 --- a/integration_tests/dbt_project.yml +++ b/integration_tests/dbt_project.yml @@ -4,7 +4,7 @@ version: '0.6.0' profile: 'integration_tests' vars: iterable_source: - iterable_schema: iterable_integration_tests + iterable_schema: dbt_jamie iterable_campaign_history_identifier: "campaign_history_data" iterable_campaign_label_history_identifier: "campaign_label_history_data" iterable_campaign_list_history_identifier: "campaign_list_history_data" diff --git a/models/intermediate/int_iterable__list_user_history.sql b/models/intermediate/int_iterable__list_user_history.sql index f0b6d90..2692181 100644 --- a/models/intermediate/int_iterable__list_user_history.sql +++ b/models/intermediate/int_iterable__list_user_history.sql @@ -26,7 +26,7 @@ with user_history as ( updated_at from previous_email_list_ids - where email_list_ids != previous_ids -- list ids are always stored in their arrays in numerical order + where email_list_ids != coalesce(previous_ids, 'this is new') -- list ids are always stored in their arrays in numerical order ), most_recent_list_ids as ( diff --git a/models/intermediate/int_iterable__list_user_unnest.sql b/models/intermediate/int_iterable__list_user_unnest.sql index e53c85b..edd03bf 100644 --- a/models/intermediate/int_iterable__list_user_unnest.sql +++ b/models/intermediate/int_iterable__list_user_unnest.sql @@ -1,27 +1,59 @@ -{{ config( materialized='table') }} +{{ config(materialized='table', + unique_key='unique_key', + incremental_strategy='insert_overwrite' if target.type in ('bigquery', 'spark', 'databricks') else 'delete+insert', + file_format='delta' + ) +}} -- materializing as a table because the computations here are fairly complex with user_history as ( select * - from {{ ref('int_iterable__list_user_history') }} - -/* -Unfortunately, `email_list_ids` are brought in as a JSON ARRAY, which different destinations handle completely differently. -The below code serves to extract and pivot list IDs into individual rows. -Records with an empty `email_list_ids` array will just have one row. -We are making the assumption that a user will not have more than 1000 lists. If that's wrong please open an issue! -https://github.com/fivetran/dbt_iterable/issues/new/choose -*/ + from {{ ref('int_iterable__list_user_history') }} as user_history + + {% if is_incremental() %} + where user_history.updated_at >= coalesce((select max({{this}}.updated_at) from {{ this }}), '1900-01-01') + {% endif %} + {% if target.type == 'redshift' %} -), numbers as ( - select 0 as generated_number - union - select * - from ( - {{ dbt_utils.generate_series(upper_bound=1000) }} ) -{% endif %} +), redshift_parse_email_lists as ( + + select + email, + first_name, + last_name, + user_id, + signup_date, + signup_source, + phone_number, + updated_at, + is_current, + email_list_ids, + json_parse(case when email_list_ids = '[]' then '["is_null"]' else email_list_ids end) as super_email_list_ids + + from user_history + +), unnest_email_array as ( + + select + email, + first_name, + last_name, + user_id, + signup_date, + signup_source, + phone_number, + updated_at, + is_current, + cast(email_list_ids as {{ dbt.type_string() }}) as email_list_ids, + cast(email_list_id as {{ dbt.type_string() }}) as email_list_id + + from redshift_parse_email_lists as emails, emails.super_email_list_ids as email_list_id + +{% else %} + ), unnest_email_array as ( + select email, first_name, @@ -36,8 +68,6 @@ https://github.com/fivetran/dbt_iterable/issues/new/choose case when email_list_ids != '[]' then {% if target.type == 'snowflake' %} email_list_id.value - {% elif target.type == 'redshift' %} - json_extract_array_element_text(email_list_ids, cast(numbers.generated_number as {{ dbt.type_int() }}), true) {% else %} email_list_id {% endif %} else null end @@ -46,23 +76,40 @@ https://github.com/fivetran/dbt_iterable/issues/new/choose from user_history - cross join {% if target.type == 'snowflake' %} + cross join table(flatten(cast(email_list_ids as VARIANT))) as email_list_id {% elif target.type == 'bigquery' %} + cross join unnest(JSON_EXTRACT_STRING_ARRAY(email_list_ids)) as email_list_id - {% elif target.type == 'redshift' %} - numbers - where numbers.generated_number < json_array_length(email_list_ids, true) - or (numbers.generated_number + json_array_length(email_list_ids, true) = 0) {% else %} /* postgres */ + cross join json_array_elements_text(cast(( case when email_list_ids = '[]' then '["is_null"]' -- to not remove empty array-rows else email_list_ids end) as json)) as email_list_id {%- endif %} +{%- endif -%} +), adjust_nulls as ( + + select + email, + first_name, + last_name, + user_id, + signup_date, + signup_source, + updated_at, + phone_number, + is_current, + case when email_list_ids = '["is_null"]' then '[]' else email_list_ids end as email_list_ids, + cast(NULLIF(email_list_id, 'is_null') as {{ dbt.type_int() }}) as list_id + + from unnest_email_array + ), final as ( + select email, first_name, @@ -74,8 +121,10 @@ https://github.com/fivetran/dbt_iterable/issues/new/choose phone_number, is_current, email_list_ids, - cast(email_list_id as {{ dbt.type_int() }}) as list_id - from unnest_email_array + list_id, + {{ dbt_utils.generate_surrogate_key(["email", "list_id", "updated_at"]) }} as unique_key + + from adjust_nulls ) select * From 4982b074b1a04a75c050019c98f127df118a0e42 Mon Sep 17 00:00:00 2001 From: Jamie Rodriguez <65564846+fivetran-jamie@users.noreply.github.com> Date: Wed, 26 Apr 2023 15:29:53 -0700 Subject: [PATCH 02/10] incremental models --- dbt_project.yml | 2 ++ models/intermediate/int_iterable__list_user_unnest.sql | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/dbt_project.yml b/dbt_project.yml index 995a04b..d6dfd9c 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -9,6 +9,8 @@ models: intermediate: +materialized: view +schema: int_iterable + int_iterable__list_user_history: + +materialized: table vars: iterable: campaign_history: "{{ ref('stg_iterable__campaign_history') }}" diff --git a/models/intermediate/int_iterable__list_user_unnest.sql b/models/intermediate/int_iterable__list_user_unnest.sql index edd03bf..e5ab8d5 100644 --- a/models/intermediate/int_iterable__list_user_unnest.sql +++ b/models/intermediate/int_iterable__list_user_unnest.sql @@ -1,4 +1,4 @@ -{{ config(materialized='table', +{{ config(materialized='incremental', unique_key='unique_key', incremental_strategy='insert_overwrite' if target.type in ('bigquery', 'spark', 'databricks') else 'delete+insert', file_format='delta' @@ -12,7 +12,8 @@ with user_history as ( from {{ ref('int_iterable__list_user_history') }} as user_history {% if is_incremental() %} - where user_history.updated_at >= coalesce((select max({{this}}.updated_at) from {{ this }}), '1900-01-01') + -- the only rows we potentially want to overwrite are active ones + where user_history.updated_at >= coalesce((select min({{this}}.updated_at) from {{ this }} where is_current), '2010-01-01') {% endif %} {% if target.type == 'redshift' %} From 6e7673a4accf192d2b17611095eb28fb59dca080 Mon Sep 17 00:00:00 2001 From: Jamie Rodriguez <65564846+fivetran-jamie@users.noreply.github.com> Date: Wed, 26 Apr 2023 16:02:27 -0700 Subject: [PATCH 03/10] comments --- .../int_iterable__list_user_unnest.sql | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/models/intermediate/int_iterable__list_user_unnest.sql b/models/intermediate/int_iterable__list_user_unnest.sql index e5ab8d5..18bc2cc 100644 --- a/models/intermediate/int_iterable__list_user_unnest.sql +++ b/models/intermediate/int_iterable__list_user_unnest.sql @@ -1,10 +1,10 @@ -{{ config(materialized='incremental', - unique_key='unique_key', - incremental_strategy='insert_overwrite' if target.type in ('bigquery', 'spark', 'databricks') else 'delete+insert', - file_format='delta' - ) +{{ config( + materialized='incremental', + unique_key='unique_key', + incremental_strategy='insert_overwrite' if target.type in ('bigquery', 'spark', 'databricks') else 'delete+insert', + file_format='delta' + ) }} --- materializing as a table because the computations here are fairly complex with user_history as ( @@ -12,11 +12,12 @@ with user_history as ( from {{ ref('int_iterable__list_user_history') }} as user_history {% if is_incremental() %} - -- the only rows we potentially want to overwrite are active ones + {# the only rows we potentially want to overwrite are active ones #} where user_history.updated_at >= coalesce((select min({{this}}.updated_at) from {{ this }} where is_current), '2010-01-01') {% endif %} {% if target.type == 'redshift' %} +{# using PartiQL syntax to work with redshift's SUPER types #} ), redshift_parse_email_lists as ( select @@ -30,6 +31,7 @@ with user_history as ( updated_at, is_current, email_list_ids, + {# let's not remove empty array-rows #} json_parse(case when email_list_ids = '[]' then '["is_null"]' else email_list_ids end) as super_email_list_ids from user_history @@ -46,13 +48,13 @@ with user_history as ( phone_number, updated_at, is_current, - cast(email_list_ids as {{ dbt.type_string() }}) as email_list_ids, + {# go back to strings #} + cast(email_list_ids as {{ dbt.type_string() }}) as email_list_ids, cast(email_list_id as {{ dbt.type_string() }}) as email_list_id from redshift_parse_email_lists as emails, emails.super_email_list_ids as email_list_id {% else %} - ), unnest_email_array as ( select @@ -69,11 +71,7 @@ with user_history as ( case when email_list_ids != '[]' then {% if target.type == 'snowflake' %} email_list_id.value - {% else %} email_list_id - {% endif %} - else null end - as - email_list_id + {% else %} email_list_id {% endif %} else null end as email_list_id from user_history @@ -84,10 +82,10 @@ with user_history as ( cross join unnest(JSON_EXTRACT_STRING_ARRAY(email_list_ids)) as email_list_id {% else %} - /* postgres */ + {# postgres #} cross join json_array_elements_text(cast(( - case when email_list_ids = '[]' then '["is_null"]' -- to not remove empty array-rows + case when email_list_ids = '[]' then '["is_null"]' {# to not remove empty array-rows #} else email_list_ids end) as json)) as email_list_id {%- endif %} From 170515fb8221757803ce120df793005d4622ab0c Mon Sep 17 00:00:00 2001 From: Jamie Rodriguez <65564846+fivetran-jamie@users.noreply.github.com> Date: Thu, 27 Apr 2023 12:46:24 -0700 Subject: [PATCH 04/10] draft pr --- CHANGELOG.md | 11 +++++++++++ dbt_project.yml | 2 +- integration_tests/dbt_project.yml | 4 ++-- .../intermediate/int_iterable__list_user_unnest.sql | 3 ++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac9acfd..830a06c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +# dbt_iterable v0.7.0 +PR #update adds the following changes: + +## 🚨 Breaking Changes 🚨 +- Adjusts the default materialization of `int_iterable__list_user_history` from a view to a table. This was changed to optimize the runtime of the downstream `int_iterable__list_user_unnest` model. +- Updates `int_iterable__list_user_unnest` to be materialized as an incremental table. In order to add this logic, we also added a new `unique_key` field -- a surrogate key hashed on `email`, `list_id`, and `updated_at`. + - **You will need to run a full refresh first to pick up the new column**. + +## Under the Hood +- Adds a `coalesce` to `previous_email_ids` in the `int_iterable__list_user_history` model, in case there are no previous email ids. + # dbt_iterable v0.6.0 ## 🚨 Breaking Changes 🚨 diff --git a/dbt_project.yml b/dbt_project.yml index d6dfd9c..372bdc9 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -1,5 +1,5 @@ name: 'iterable' -version: '0.6.0' +version: '0.7.0' config-version: 2 require-dbt-version: [">=1.3.0", "<2.0.0"] models: diff --git a/integration_tests/dbt_project.yml b/integration_tests/dbt_project.yml index 472b53f..dac10e0 100644 --- a/integration_tests/dbt_project.yml +++ b/integration_tests/dbt_project.yml @@ -1,10 +1,10 @@ config-version: 2 name: 'iterable_integration_tests' -version: '0.6.0' +version: '0.7.0' profile: 'integration_tests' vars: iterable_source: - iterable_schema: dbt_jamie + iterable_schema: iterable_integration_tests iterable_campaign_history_identifier: "campaign_history_data" iterable_campaign_label_history_identifier: "campaign_label_history_data" iterable_campaign_list_history_identifier: "campaign_list_history_data" diff --git a/models/intermediate/int_iterable__list_user_unnest.sql b/models/intermediate/int_iterable__list_user_unnest.sql index 18bc2cc..5b76237 100644 --- a/models/intermediate/int_iterable__list_user_unnest.sql +++ b/models/intermediate/int_iterable__list_user_unnest.sql @@ -2,7 +2,8 @@ materialized='incremental', unique_key='unique_key', incremental_strategy='insert_overwrite' if target.type in ('bigquery', 'spark', 'databricks') else 'delete+insert', - file_format='delta' + file_format='delta', + on_schema_change='fail' ) }} From 17e9a6b4909ea8304fe735ae11859a6fecfbcd03 Mon Sep 17 00:00:00 2001 From: Jamie Rodriguez <65564846+fivetran-jamie@users.noreply.github.com> Date: Thu, 27 Apr 2023 12:48:50 -0700 Subject: [PATCH 05/10] made PR --- CHANGELOG.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 830a06c..8daa73c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # dbt_iterable v0.7.0 -PR #update adds the following changes: +[PR #28](https://github.com/fivetran/dbt_iterable/pull/28) adds the following changes: ## 🚨 Breaking Changes 🚨 - Adjusts the default materialization of `int_iterable__list_user_history` from a view to a table. This was changed to optimize the runtime of the downstream `int_iterable__list_user_unnest` model. diff --git a/README.md b/README.md index 474c651..ee8589b 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Include the following Iterable package version in your `packages.yml` file. ```yaml packages: - package: fivetran/iterable - version: [">=0.6.0", "<0.7.0"] + version: [">=0.7.0", "<0.8.0"] ``` ## Step 3: Define database and schema variables By default, this package runs using your destination and the `iterable` schema of your [target database](https://docs.getdbt.com/docs/running-a-dbt-project/using-the-command-line-interface/configure-your-profile). If this is not where your Iterable data is located (for example, if your Iterable schema is named `iterable_fivetran`), add the following configuration to your root `dbt_project.yml` file: From bcc90114ba3d462391f7b9dd3ef844610af4f406 Mon Sep 17 00:00:00 2001 From: Jamie Rodriguez <65564846+fivetran-jamie@users.noreply.github.com> Date: Mon, 1 May 2023 13:51:02 -0700 Subject: [PATCH 06/10] test incrememtnal run --- .buildkite/scripts/run_models.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.buildkite/scripts/run_models.sh b/.buildkite/scripts/run_models.sh index 8462cc6..18c7d9a 100644 --- a/.buildkite/scripts/run_models.sh +++ b/.buildkite/scripts/run_models.sh @@ -17,7 +17,10 @@ echo `pwd` cd integration_tests dbt deps dbt seed --target "$db" --full-refresh +dbt compile --target "$db" dbt run --target "$db" --full-refresh +dbt run --target "$db" dbt test --target "$db" dbt run --vars '{iterable__using_campaign_label_history: false, iterable__using_user_unsubscribed_message_type_history: false, iterable__using_campaign_suppression_list_history: false, iterable__using_user_device_history: true}' --target "$db" --full-refresh +dbt run --vars '{iterable__using_campaign_label_history: false, iterable__using_user_unsubscribed_message_type_history: false, iterable__using_campaign_suppression_list_history: false, iterable__using_user_device_history: true}' --target "$db" dbt test --target "$db" \ No newline at end of file From 9a7639fb90abcc38faad180f961ddbbd11fa679e Mon Sep 17 00:00:00 2001 From: Jamie Rodriguez <65564846+fivetran-jamie@users.noreply.github.com> Date: Tue, 2 May 2023 10:34:24 -0700 Subject: [PATCH 07/10] add partition --- models/intermediate/int_iterable__list_user_unnest.sql | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/models/intermediate/int_iterable__list_user_unnest.sql b/models/intermediate/int_iterable__list_user_unnest.sql index 5b76237..ad82352 100644 --- a/models/intermediate/int_iterable__list_user_unnest.sql +++ b/models/intermediate/int_iterable__list_user_unnest.sql @@ -2,6 +2,7 @@ materialized='incremental', unique_key='unique_key', incremental_strategy='insert_overwrite' if target.type in ('bigquery', 'spark', 'databricks') else 'delete+insert', + partition_by={"field": "date_day", "data_type": "date"} if target.type not in ('spark','databricks') else ['date_day'], file_format='delta', on_schema_change='fail' ) @@ -14,7 +15,7 @@ with user_history as ( {% if is_incremental() %} {# the only rows we potentially want to overwrite are active ones #} - where user_history.updated_at >= coalesce((select min({{this}}.updated_at) from {{ this }} where is_current), '2010-01-01') + where user_history.updated_at >= coalesce((select min(updated_at) from {{ this }} where is_current), '2010-01-01') {% endif %} {% if target.type == 'redshift' %} @@ -122,7 +123,8 @@ with user_history as ( is_current, email_list_ids, list_id, - {{ dbt_utils.generate_surrogate_key(["email", "list_id", "updated_at"]) }} as unique_key + {{ dbt_utils.generate_surrogate_key(["email", "list_id", "updated_at"]) }} as unique_key, + cast( {{ dbt.date_trunc('day', 'updated_at') }} as date) as date_day from adjust_nulls ) From 3eeebba57b3b4d459b6979ec175bfbea583c55c4 Mon Sep 17 00:00:00 2001 From: Jamie Rodriguez <65564846+fivetran-jamie@users.noreply.github.com> Date: Tue, 2 May 2023 10:53:40 -0700 Subject: [PATCH 08/10] seed cast --- integration_tests/dbt_project.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/integration_tests/dbt_project.yml b/integration_tests/dbt_project.yml index dac10e0..b63e1a8 100644 --- a/integration_tests/dbt_project.yml +++ b/integration_tests/dbt_project.yml @@ -43,4 +43,7 @@ seeds: channel_id: "{%- if target.type == 'bigquery' -%} INT64 {%- else -%} bigint {%- endif -%}" user_unsubscribed_message_type_history_data: +column_types: - message_type_id: "{%- if target.type == 'bigquery' -%} INT64 {%- else -%} bigint {%- endif -%}" \ No newline at end of file + message_type_id: "{%- if target.type == 'bigquery' -%} INT64 {%- else -%} bigint {%- endif -%}" + user_history_data: + +column_types: + updated_at: timestamp \ No newline at end of file From a4f47e81940da2c67097b4f86b03bc920f75d2c3 Mon Sep 17 00:00:00 2001 From: Jamie Rodriguez <65564846+fivetran-jamie@users.noreply.github.com> Date: Tue, 2 May 2023 11:19:39 -0700 Subject: [PATCH 09/10] changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8daa73c..3a37889 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,8 @@ ## 🚨 Breaking Changes 🚨 - Adjusts the default materialization of `int_iterable__list_user_history` from a view to a table. This was changed to optimize the runtime of the downstream `int_iterable__list_user_unnest` model. -- Updates `int_iterable__list_user_unnest` to be materialized as an incremental table. In order to add this logic, we also added a new `unique_key` field -- a surrogate key hashed on `email`, `list_id`, and `updated_at`. - - **You will need to run a full refresh first to pick up the new column**. +- Updates `int_iterable__list_user_unnest` to be materialized as an incremental table. In order to add this logic, we also added a new `unique_key` field -- a surrogate key hashed on `email`, `list_id`, and `updated_at` -- and a `date_day` field to partition by on Bigquery + Databricks. + - **You will need to run a full refresh first to pick up the new columns**. ## Under the Hood - Adds a `coalesce` to `previous_email_ids` in the `int_iterable__list_user_history` model, in case there are no previous email ids. From e2219caf6d90357e3eaf88084ee5416e94e2eaa7 Mon Sep 17 00:00:00 2001 From: Jamie Rodriguez <65564846+fivetran-jamie@users.noreply.github.com> Date: Wed, 3 May 2023 10:26:57 -0700 Subject: [PATCH 10/10] snowflake --- CHANGELOG.md | 1 + integration_tests/seeds/user_history_data.csv | 14 +++++++++++--- .../int_iterable__list_user_unnest.sql | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a37889..9159855 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ## Under the Hood - Adds a `coalesce` to `previous_email_ids` in the `int_iterable__list_user_history` model, in case there are no previous email ids. +- Adjusts the `flatten` logic in `int_iterable__list_user_unnest` for Snowflake users. # dbt_iterable v0.6.0 diff --git a/integration_tests/seeds/user_history_data.csv b/integration_tests/seeds/user_history_data.csv index 084742a..8106402 100644 --- a/integration_tests/seeds/user_history_data.csv +++ b/integration_tests/seeds/user_history_data.csv @@ -1,3 +1,11 @@ -email,updated_at,first_name,last_name,phone_number,user_id,signup_date,signup_source,phone_number_carrier,phone_number_country_code_iso,phone_number_line_type,phone_number_updated_at,_fivetran_synced,email_list_ids -glennclose@hoodwinked.com,2021-06-03 08:18:30.000,,,,,2021-06-03 08:14:55.000,Import,,,,,2021-06-03 09:18:13.877,"[826724,884398]" -innitluv@theguardian.co.uk,2021-06-03 08:32:01.000,,,,,2021-06-03 08:32:01.000,API,,,,,2021-06-03 09:18:13.708,"[]" \ No newline at end of file +email,updated_at,_fivetran_synced,email_list_ids,first_name,last_name,phone_number,phone_number_carrier,phone_number_country_code_iso,phone_number_details,phone_number_line_type,phone_number_updated_at,signup_date,signup_source,user_id +person1@email.com,2018-09-14 08:29:13,2021-03-29 17:14:01,[162418],,,,,,,,,2018-09-14 08:29:13,Import, +person2@email.com,2018-09-18 17:24:11,2021-03-29 17:14:01,[163833],,,,,,,,,2018-09-18 17:22:15,API, +person3@email.com,2018-09-19 10:06:24,2021-03-29 17:14:01,[164228],,,,,,,,,2018-09-19 10:06:24,Import,22222 +person4@email.com,2018-10-05 05:37:24,2021-03-29 17:14:01,"[159258,159261,162418]",person4,,,,,,,,2018-09-06 10:18:17,Import,string +person5@email.com,2018-10-05 05:46:47,2021-03-29 17:14:01,"[159246,159258,159261,162418,163833,173413]",person5,five,,ZZZ,0,,Phone,,2018-09-06 9:11:43,Import,1111 +person6@email.com,2018-10-06 11:36:18,2021-03-29 17:14:01,[173950],,,,,,,,,2018-10-06 11:36:18,Import, +person7@email.com,2021-04-20 20:31:29,2021-04-20 20:56:40,[953900],,,,,,,,,2021-04-20 20:31:30,Import, +person8@email.com,2021-04-20 20:43:37,2021-04-20 20:56:40,[953900],,,,,,,,,2021-04-20 20:30:16,Import, +person9@gmail.com,2021-04-21 20:21:29,2021-04-21 20:28:04,[],,,,,,,,,2021-04-21 20:21:29,API,person_test +person8@email.com,2021-04-21 20:59:40,2021-04-21 21:01:52,[953900],,,,,,,,,2021-04-20 20:30:16,Import, \ No newline at end of file diff --git a/models/intermediate/int_iterable__list_user_unnest.sql b/models/intermediate/int_iterable__list_user_unnest.sql index ad82352..1f7d21a 100644 --- a/models/intermediate/int_iterable__list_user_unnest.sql +++ b/models/intermediate/int_iterable__list_user_unnest.sql @@ -79,7 +79,7 @@ with user_history as ( {% if target.type == 'snowflake' %} cross join - table(flatten(cast(email_list_ids as VARIANT))) as email_list_id + table(flatten(input => parse_json(email_list_ids))) as email_list_id {% elif target.type == 'bigquery' %} cross join unnest(JSON_EXTRACT_STRING_ARRAY(email_list_ids)) as email_list_id