Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# dbt_apple_store v1.3.0

[PR #50](https://github.com/fivetran/dbt_apple_store/pull/50) includes the following updates:

## Schema/Data Changes (--full-refresh required after upgrading)
**1 total change • 1 possible breaking change**

| Data Model(s) | Change type | Old | New | Notes |
| ------------- | ----------- | --- | --- | ----- |
| All models | `source_relation` column (when using a single Apple Store schema) | Empty string (`''`) | `<database>.<schema>` | |

## Feature Updates
- Introduces the new (recommended) `apple_store_sources` variable for more robust union data configuration. The old `apple_store_union_schemas` and `apple_store_union_databases` variables will still be supported. See the [README](https://github.com/fivetran/dbt_apple_store/tree/main#define-database-and-schema-variables) for specific details.

## Under the Hood
- Adds the `fivetran_using_source_casing` variable for case-sensitive destination support. When enabled, downstream transformations respect source casing to ensure consistent results. See the [Additional Configurations](https://github.com/fivetran/dbt_apple_store/#source-casing-for-case-sensitive-destinations) section of the README for details.
- Introduces `fivetran_utils.partition_by_source_relation` to conditionally include `source_relation` in partition clauses only when multiple sources are configured.

# dbt_apple_store v1.2.0

[PR #45](https://github.com/fivetran/dbt_apple_store/pull/45) includes the following updates:
Expand Down
55 changes: 39 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,47 @@ Include the following apple_store package version in your `packages.yml` file:
```yaml
packages:
- package: fivetran/apple_store
version: [">=1.2.0", "<1.3.0"]
version: [">=1.3.0", "<1.4.0"]
```

> All required sources and staging models are now bundled into this transformation package. Do not include `fivetran/apple_store_source` in your `packages.yml` since this package has been deprecated.

### Define database and schema variables
By default, this package runs using your destination and the `apple_store` schema. If this is not where your apple_store data is (for example, if your apple_store schema is named `apple_store_fivetran`), add the following configuration to your root `dbt_project.yml` file:
#### Option A: Single connection
By default, this package runs using your destination and the `apple_store` schema. If this is not where your Apple Store data is (for example, if your Apple Store schema is named `apple_store_fivetran`), add the following configuration to your root `dbt_project.yml` file:

```yml
vars:
apple_store_database: your_destination_name
apple_store_schema: your_schema_name
apple_store_schema: your_schema_name
```

#### Option B: Union multiple connections
If you have multiple Apple Store connections in Fivetran and would like to use this package on all of them simultaneously, we have provided functionality to do so. For each source table, the package will union all of the data together and pass the unioned table into the transformations. The `source_relation` column in each model indicates the origin of each record.

To use this functionality, you will need to set the `apple_store_sources` variable in your root `dbt_project.yml` file:

```yml
# dbt_project.yml

vars:
apple_store:
apple_store_sources:
- database: connection_1_destination_name # Required
schema: connection_1_schema_name # Required
name: connection_1_source_name # Required only if following the step in the following subsection

- database: connection_2_destination_name
schema: connection_2_schema_name
name: connection_2_source_name
```

> Previous versions of this package employed two separate, mutually exclusive variables for unioning: `apple_store_union_schemas` and `apple_store_union_databases`. While these variables are still supported, `apple_store_sources` is the recommended variable to configure.

#### Optional: Incorporate unioned sources into DAG

If you use [Fivetran Transformations for dbt Core™](https://fivetran.com/docs/transformations/dbt#transformationsfordbtcore) and are unioning multiple Apple Store connections, you can define your sources in a property `.yml` file, [using this as a template](https://github.com/fivetran/dbt_apple_store/blob/main/models/staging/src_apple_store.yml). Set the variable `has_defined_sources: true` under the Apple Store namespace in your `dbt_project.yml`. Otherwise, your Apple Store connections won't appear in your DAG. See the `union_connections` macro [documentation](https://github.com/fivetran/dbt_fivetran_utils/tree/releases/v0.4.latest#optional-union-connections-defined-sources-configuration) for full configuration details.

### Disable models for non-existent sources
Your Apple App Store connection might not sync every table that this package expects. If you use subscriptions and have the `sales_subscription_event_summary` and `sales_subscription_summary` tables synced, add the following variable to your `dbt_project.yml` file:

Expand All @@ -96,18 +123,6 @@ You will need to `dbt seed` the `apple_store_country_codes` [file](https://githu
### (Optional) Additional configurations
<details open><summary>Expand/collapse configurations</summary>

#### Union multiple connections
If you have multiple apple_store connections in Fivetran and would like to use this package on all of them simultaneously, we have provided functionality to do so. The package will union all of the data together and pass the unioned table into the transformations. You will be able to see which source it came from in the `source_relation` column of each model. To use this functionality, you will need to set either the `apple_store_union_schemas` OR `apple_store_union_databases` variables (cannot do both) in your root `dbt_project.yml` file:

```yml
vars:
apple_store_union_schemas: ['apple_store_usa','apple_store_canada'] # use this if the data is in different schemas/datasets of the same database/project
apple_store_union_databases: ['apple_store_usa','apple_store_canada'] # use this if the data is in different databases/projects but uses the same schema name
```
> NOTE: The native `source.yml` connection set up in the package will not function when the union schema/database feature is utilized. Although the data will be correctly combined, you will not observe the sources linked to the package models in the Directed Acyclic Graph (DAG). This happens because the package includes only one defined `source.yml`.

To connect your multiple schema/database sources to the package models, follow the steps outlined in the [Union Data Defined Sources Configuration](https://github.com/fivetran/dbt_fivetran_utils/tree/releases/v0.4.latest#union_data-source) section of the Fivetran Utils documentation for the union_data macro. This will ensure a proper configuration and correct visualization of connections in the DAG.

#### Defining subscription events
By default, `Subscribe`, `Renew` and `Cancel` subscription events are included and required in this package for downstream usage. If you would like to add additional subscription events, please add the below to your `dbt_project.yml`:

Expand Down Expand Up @@ -140,6 +155,14 @@ If an individual source table has a different name than the package expects, add
vars:
apple_store_<default_source_table_name>_identifier: your_table_name
```

#### Source casing for case-sensitive destinations
By default, the package applies case-insensitive comparisons when resolving `source_relation` values. If your destination is case-sensitive and you want downstream transformations to respect the exact casing of your source database and schema names, set the following variable:

```yml
vars:
fivetran_using_source_casing: true
```
</details>

### (Optional) Orchestrate your models with Fivetran Transformations for dbt Core™
Expand Down Expand Up @@ -183,4 +206,4 @@ In creating this package, which is meant for a wide range of use cases, we had t

## Are there any resources available?
- If you have questions or want to reach out for help, see the [GitHub Issue](https://github.com/fivetran/dbt_apple_store/issues/new/choose) section to find the right avenue of support for you.
- If you would like to provide feedback to the dbt package team at Fivetran or would like to request a new dbt package, fill out our [Feedback Form](https://www.surveymonkey.com/r/DQ7K7WW).
- If you would like to provide feedback to the dbt package team at Fivetran or would like to request a new dbt package, fill out our [Feedback Form](https://www.surveymonkey.com/r/DQ7K7WW).
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'apple_store'
version: '1.2.0'
version: '1.3.0'
config-version: 2
require-dbt-version: [">=1.3.0", "<3.0.0"]
vars:
Expand Down
2 changes: 1 addition & 1 deletion docs/catalog.json

Large diffs are not rendered by default.

253 changes: 3 additions & 250 deletions docs/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/manifest.json

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion integration_tests/ci/test_scenarios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ test_scenarios:
- name: "subscriptions enabled"
vars:
apple_store__using_subscriptions: true
include_incremental: false
include_incremental: false

- name: "MDLS"
vars:
fivetran_using_source_casing: true
include_incremental: false
include_dbt_seed: true
4 changes: 2 additions & 2 deletions integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
config-version: 2

name: 'apple_store_integration_tests'
version: '1.2.0'
version: '1.3.0'

profile: 'integration_tests'

Expand Down Expand Up @@ -33,7 +33,7 @@ seeds:
+docs:
show: False
apple_store_integration_tests:
+quote_columns: "{{ true if target.type == 'redshift' else false }}"
+quote_columns: "{{ target.type == 'redshift' or var('fivetran_using_source_casing', false) }}"
app_crash_daily:
+column_types:
_fivetran_synced: timestamp
Expand Down
5 changes: 3 additions & 2 deletions models/staging/src_apple_store.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ sources:

config:
loaded_at_field: _fivetran_synced
enabled: "{{ var('apple_store_sources', []) == [] }}"
freshness:
warn_after: {count: 48, period: hour}
error_after: {count: 168, period: hour}
Expand All @@ -28,7 +29,7 @@ sources:
identifier: "{{ var('apple_store_sales_subscription_event_summary_identifier', 'sales_subscription_event_summary')}}"
description: Daily subscription event report by account ID, app name, subscription name, event, country, state and device; this model is aggregated by date, app_name, account_id, country, state and subscription_name for easier transformations in the modeling package.
config:
enabled: "{{ var('apple_store__using_subscriptions', false) }}"
enabled: "{{ var('apple_store__using_subscriptions', false) and var('apple_store_sources', []) == [] }}"
columns:
- name: _fivetran_id
description: '{{ doc("_fivetran_id") }}'
Expand Down Expand Up @@ -99,7 +100,7 @@ sources:
identifier: "{{ var('apple_store_sales_subscription_summary_identifier', 'sales_subscription_summary')}}"
description: Daily subscription summary report by account ID, app name, country, state and subscription name; this model is aggregated by date, app_name, account_id, country, state and subscription_name for easier transformations in the modeling package.
config:
enabled: "{{ var('apple_store__using_subscriptions', false) }}"
enabled: "{{ var('apple_store__using_subscriptions', false) and var('apple_store_sources', []) == [] }}"
columns:
- name: _fivetran_id
description: '{{ doc("_fivetran_id") }}'
Expand Down
7 changes: 2 additions & 5 deletions models/staging/stg_apple_store__app_crash_daily.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ fields as (
)
}}

{{ fivetran_utils.source_relation(
union_schema_variable='apple_store_union_schemas',
union_database_variable='apple_store_union_databases')
}}
{{ fivetran_utils.apply_source_relation(package_name='apple_store') }}

from base

Expand All @@ -42,4 +39,4 @@ final as (
)

select *
from final
from final
7 changes: 2 additions & 5 deletions models/staging/stg_apple_store__app_session_daily.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ fields as (
)
}}

{{ fivetran_utils.source_relation(
union_schema_variable='apple_store_union_schemas',
union_database_variable='apple_store_union_databases')
}}
{{ fivetran_utils.apply_source_relation(package_name='apple_store') }}

from base

Expand Down Expand Up @@ -46,4 +43,4 @@ final as (
)

select *
from final
from final
7 changes: 2 additions & 5 deletions models/staging/stg_apple_store__app_store_app.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ fields as (
}}


{{ fivetran_utils.source_relation(
union_schema_variable='apple_store_union_schemas',
union_database_variable='apple_store_union_databases')
}}
{{ fivetran_utils.apply_source_relation(package_name='apple_store') }}

from base
),
Expand All @@ -34,4 +31,4 @@ final as (
)

select *
from final
from final
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ fields as (
)
}}

{{ fivetran_utils.source_relation(
union_schema_variable='apple_store_union_schemas',
union_database_variable='apple_store_union_databases')
}}
{{ fivetran_utils.apply_source_relation(package_name='apple_store') }}

from base

Expand All @@ -45,4 +42,4 @@ final as (
)

select *
from final
from final
7 changes: 2 additions & 5 deletions models/staging/stg_apple_store__app_store_download_daily.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ fields as (
)
}}

{{ fivetran_utils.source_relation(
union_schema_variable='apple_store_union_schemas',
union_database_variable='apple_store_union_databases')
}}
{{ fivetran_utils.apply_source_relation(package_name='apple_store') }}

from base

Expand All @@ -45,4 +42,4 @@ final as (
)

select *
from final
from final
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ fields as (
)
}}

{{ fivetran_utils.source_relation(
union_schema_variable='apple_store_union_schemas',
union_database_variable='apple_store_union_databases')
}}
{{ fivetran_utils.apply_source_relation(package_name='apple_store') }}

from base

Expand Down Expand Up @@ -47,4 +44,4 @@ final as (
)

select *
from final
from final
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ fields as (
}}


{{ fivetran_utils.source_relation(
union_schema_variable='apple_store_union_schemas',
union_database_variable='apple_store_union_databases')
}}
{{ fivetran_utils.apply_source_relation(package_name='apple_store') }}

from base
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ fields as (
}}


{{ fivetran_utils.source_relation(
union_schema_variable='apple_store_union_schemas',
union_database_variable='apple_store_union_databases')
}}
{{ fivetran_utils.apply_source_relation(package_name='apple_store') }}

from base
),
Expand Down
14 changes: 14 additions & 0 deletions models/staging/tmp/stg_apple_store__app_crash_tmp.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% if var('apple_store_union_schemas', []) | length > 0 or var('apple_store_union_databases', []) | length > 0 %}

{{
fivetran_utils.union_data(
table_identifier='app_crash_daily',
Expand All @@ -10,3 +12,15 @@
union_database_variable='apple_store_union_databases'
)
}}

{% else %}

{{
fivetran_utils.union_connections(
connection_dictionary='apple_store_sources',
single_source_name='apple_store',
single_table_name='app_crash_daily'
)
}}

{% endif %}
14 changes: 14 additions & 0 deletions models/staging/tmp/stg_apple_store__app_session_tmp.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% if var('apple_store_union_schemas', []) | length > 0 or var('apple_store_union_databases', []) | length > 0 %}

{{
fivetran_utils.union_data(
table_identifier='app_session_standard_daily',
Expand All @@ -10,3 +12,15 @@
union_database_variable='apple_store_union_databases'
)
}}

{% else %}

{{
fivetran_utils.union_connections(
connection_dictionary='apple_store_sources',
single_source_name='apple_store',
single_table_name='app_session_standard_daily'
)
}}

{% endif %}
16 changes: 15 additions & 1 deletion models/staging/tmp/stg_apple_store__app_store_app_tmp.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% if var('apple_store_union_schemas', []) | length > 0 or var('apple_store_union_databases', []) | length > 0 %}

{{
fivetran_utils.union_data(
table_identifier='app_store_app',
Expand All @@ -9,4 +11,16 @@
union_schema_variable='apple_store_union_schemas',
union_database_variable='apple_store_union_databases'
)
}}
}}

{% else %}

{{
fivetran_utils.union_connections(
connection_dictionary='apple_store_sources',
single_source_name='apple_store',
single_table_name='app_store_app'
)
}}

{% endif %}
Loading