diff --git a/dbt_project.yml b/dbt_project.yml index 85f68a3..fc65b5f 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -34,6 +34,9 @@ vars: intercom__contact_history_pass_through_columns: [] intercom__conversation_history_pass_through_columns: [] intercom__article_history_pass_through_columns: [] +dispatch: + - macro_namespace: fivetran_utils + search_order: ['intercom', 'fivetran_utils'] clean-targets: - target - dbt_modules diff --git a/integration_tests/ci/test_scenarios.yml b/integration_tests/ci/test_scenarios.yml index ba4e9fd..1ad3aa5 100644 --- a/integration_tests/ci/test_scenarios.yml +++ b/integration_tests/ci/test_scenarios.yml @@ -10,6 +10,7 @@ schema_variable_name: "intercom_schema" include_databricks_sql: false include_sqlserver: false +include_duckdb: true include_dbt_compile: true test_scenarios: diff --git a/integration_tests/dbt_project.yml b/integration_tests/dbt_project.yml index 77bef1f..c82c5af 100644 --- a/integration_tests/dbt_project.yml +++ b/integration_tests/dbt_project.yml @@ -195,6 +195,8 @@ seeds: dispatch: - macro_namespace: dbt_utils search_order: ['spark_utils', 'dbt_utils'] + - macro_namespace: fivetran_utils + search_order: ['intercom', 'fivetran_utils'] flags: send_anonymous_usage_stats: False diff --git a/macros/duckdb__percentile.sql b/macros/duckdb__percentile.sql new file mode 100644 index 0000000..b974254 --- /dev/null +++ b/macros/duckdb__percentile.sql @@ -0,0 +1,7 @@ +--percentile calculation specific to DuckDB +{% macro duckdb__percentile(percentile_field, partition_field, percent) %} + + quantile_cont({{ percentile_field }}, {{ percent }}) + /* have to group by partition field */ + +{% endmacro %} diff --git a/models/intercom__admin_metrics.sql b/models/intercom__admin_metrics.sql index 2f4f232..2c97ebd 100644 --- a/models/intercom__admin_metrics.sql +++ b/models/intercom__admin_metrics.sql @@ -45,8 +45,8 @@ median_metrics as ( round(cast({{ fivetran_utils.percentile("conversation_metrics.time_to_first_close_minutes", "last_close_by_admin_id", "0.5") }} as numeric), 2) as median_time_to_first_close_minutes, round(cast({{ fivetran_utils.percentile("conversation_metrics.time_to_last_close_minutes", "last_close_by_admin_id", "0.5") }} as numeric), 2) as median_time_to_last_close_minutes from conversation_metrics ---The Postgres warehouse does not allow for a group by argument within the `percentile` function. As such, we will apply the group by for all statements at the end of the query for Postgres only. - {% if target.type == 'postgres' %} +--The Postgres and DuckDB warehouses do not allow for a group by argument within the `percentile` function. As such, we will apply the group by for all statements at the end of the query for Postgres and DuckDB only. + {% if target.type in ('postgres', 'duckdb') %} group by 1, 2 {% endif %} ), diff --git a/models/intercom__company_metrics.sql b/models/intercom__company_metrics.sql index ffd938d..9c1ffd3 100644 --- a/models/intercom__company_metrics.sql +++ b/models/intercom__company_metrics.sql @@ -69,8 +69,8 @@ median_metrics as ( on company_enhanced.company_id = contact_company_history.company_id and company_enhanced.source_relation = contact_company_history.source_relation ---The Postgres warehouse does not allow for a group by argument within the `percentile` function. As such, we will apply the group by for all statements at the end of the query for Postgres only. - {% if target.type == 'postgres' %} +--The Postgres and DuckDB warehouses do not allow for a group by argument within the `percentile` function. As such, we will apply the group by for all statements at the end of the query for Postgres and DuckDB only. + {% if target.type in ('postgres', 'duckdb') %} group by 1, 2 {% endif %} ),