Skip to content

Commit

Permalink
Feature: Union schema compatibility (#14)
Browse files Browse the repository at this point in the history
* MagicBot/add-union-schema updates

* revisions from automated results

* update groups

* update identifiers

* update for buildkite

* update casts

* cast ids

* cast strings

* fix typos

* update readme & changelog

* update config & move docs

* update cast

* update changelog and add autoreleaser

* regen docs
  • Loading branch information
fivetran-catfritz authored Jul 23, 2024
1 parent 08045a2 commit fce24ad
Show file tree
Hide file tree
Showing 46 changed files with 647 additions and 301 deletions.
2 changes: 1 addition & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ steps:
commands: |
bash .buildkite/scripts/run_models.sh redshift
- label: ":bricks: Run Tests - Databricks"
- label: ":databricks: Run Tests - Databricks"
key: "run_dbt_databricks"
plugins:
- docker#v3.13.0:
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/auto-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: 'auto release'
on:
pull_request:
types:
- closed
branches:
- main

jobs:
call-workflow-passing-data:
if: github.event.pull_request.merged
uses: fivetran/dbt_package_automations/.github/workflows/auto-release.yml@main
secrets: inherit
40 changes: 40 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,43 @@
# dbt_apple_store_source v0.4.0
[PR #14](https://github.com/fivetran/dbt_apple_store_source/pull/14) includes the following updates:

## 🚨 Breaking Changes 🚨
- Updated the source identifier format for consistency with other packages and for compatibility with the `fivetran_utils.union_data` macro. The identifier variables now are:

previous | current
--------|---------
`app_identifier` | `apple_store_app_identifier`
`app_store_platform_version_source_type_report_identifier` | `apple_store_app_store_platform_version_source_type_report_identifier`
`app_store_source_type_device_report_identifier` | `apple_store_app_store_source_type_device_report_identifier`
`app_store_territory_source_type_report_identifier` | `apple_store_app_store_territory_source_type_report_identifier`
`crashes_app_version_device_report_identifier` | `apple_store_crashes_app_version_device_report_identifier`
`crashes_platform_version_device_report_identifier` | `apple_store_crashes_platform_version_device_report_identifier`
`downloads_platform_version_source_type_report_identifier` | `apple_store_downloads_platform_version_source_type_report_identifier`
`downloads_source_type_device_report_identifier` | `apple_store_downloads_source_type_device_report_identifier`
`downloads_territory_source_type_report_identifier` | `apple_store_downloads_territory_source_type_report_identifier`
`sales_account_identifier` | `apple_store_sales_account_identifier`
`sales_subscription_event_summary_identifier` | `apple_store_sales_subscription_event_summary_identifier`
`sales_subscription_summary_identifier` | `apple_store_sales_subscription_summary_identifier`
`usage_app_version_source_type_report_identifier` | `apple_store_usage_app_version_source_type_report_identifier`
`usage_platform_version_source_type_report_identifier` | `apple_store_usage_platform_version_source_type_report_identifier`
`usage_source_type_device_report_identifier` | `apple_store_usage_source_type_device_report_identifier`
`usage_territory_source_type_report_identifier` | `apple_store_usage_territory_source_type_report_identifier`

- If you are using the previous identifier, be sure to update to the current version!

## Feature update 🎉
- Unioning capability! This adds the ability to union source data from multiple apple_store connectors. Refer to the [README](https://github.com/fivetran/dbt_apple_store_source/blob/main/README.md#union-multiple-connectors) for more details.
- Added a `source_relation` column in each staging model for tracking the source of each record.
- Updated tests to account for the new `source_relation` column.
- Added casting to staging columns that are used in any downstream COALESCEs, UNIONs, or JOINs to prevent datatype conflicts.
- Metric fields, such as `crashes`, `impressions`, `page_views`, etc., are now cast as the datatype determined by the `dbt.type_bigint()` macro for your warehouse.

## Under the hood 🚘
- Updated tmp models to union source data using the `fivetran_utils.union_data` macro.
- Applied the `fivetran_utils.source_relation` macro in each staging model to determine the `source_relation`.
- Updated `src_apple_store.yml` to use the current method to enable/disable sources.
- Included auto-releaser GitHub Actions workflow to automate future releases.

# dbt_apple_store_source v0.3.1

## Bug Fix
Expand Down
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Include the following apple_store_source package version in your `packages.yml`
```yaml
packages:
- package: fivetran/apple_store_source
version: [">=0.3.0", "<0.4.0"] # we recommend using ranges to capture non-breaking changes automatically
version: [">=0.4.0", "<0.5.0"] # we recommend using ranges to capture non-breaking changes automatically
```
## Step 3: 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:
Expand All @@ -56,7 +56,19 @@ In order to map longform territory names to their ISO country codes, we have ada
You will need to `dbt seed` the `apple_store_country_codes` [file](https://github.com/fivetran/dbt_apple_store_source/blob/main/seeds/apple_store_country_codes.csv) just once.

## (Optional) Step 6: Additional configurations
<details><summary>Expand to view configurations</summary>
<details open><summary>Expand/collapse configurations</summary>

### Union multiple connectors
If you have multiple apple_store connectors 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
```
Please be aware that 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 @@ -85,7 +97,7 @@ If an individual source table has a different name than the package expects, add

```yml
vars:
<default_source_table_name>_identifier: your_table_name
apple_store_<default_source_table_name>_identifier: your_table_name
```

</details>
Expand Down
18 changes: 9 additions & 9 deletions dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
name: 'apple_store_source'
version: '0.3.2'
version: '0.4.0'
config-version: 2
require-dbt-version: [">=1.3.0", "<2.0.0"]
vars:
apple_store_source:
app: "{{ source('apple_store', 'app') }}"
app_store_device: "{{ source('apple_store', 'app_store_source_type_device_report') }}"
usage_device: "{{ source('apple_store', 'usage_source_type_device_report') }}"
downloads_device: "{{ source('apple_store', 'downloads_source_type_device_report') }}"
app_store_territory: "{{ source('apple_store', 'app_store_territory_source_type_report') }}"
downloads_territory: "{{ source('apple_store', 'downloads_territory_source_type_report') }}"
usage_territory: "{{ source('apple_store', 'usage_territory_source_type_report') }}"
app_store_platform_version: "{{ source('apple_store', 'app_store_platform_version_source_type_report') }}"
app_store_territory: "{{ source('apple_store', 'app_store_territory_source_type_report') }}"
crashes_app_version: "{{ source('apple_store', 'crashes_app_version_device_report') }}"
crashes_platform_version: "{{ source('apple_store', 'crashes_platform_version_device_report') }}"
downloads_device: "{{ source('apple_store', 'downloads_source_type_device_report') }}"
downloads_platform_version: "{{ source('apple_store', 'downloads_platform_version_source_type_report') }}"
usage_platform_version: "{{ source('apple_store', 'usage_platform_version_source_type_report') }}"
crashes_app_version: "{{ source('apple_store', 'crashes_app_version_device_report') }}"
usage_app_version: "{{ source('apple_store', 'usage_app_version_source_type_report') }}"
downloads_territory: "{{ source('apple_store', 'downloads_territory_source_type_report') }}"
sales_account: "{{ source('apple_store', 'sales_account') }}"
sales_subscription_events: "{{ source('apple_store', 'sales_subscription_event_summary') }}"
sales_subscription_summary: "{{ source('apple_store', 'sales_subscription_summary') }}"
usage_app_version: "{{ source('apple_store', 'usage_app_version_source_type_report') }}"
usage_device: "{{ source('apple_store', 'usage_source_type_device_report') }}"
usage_platform_version: "{{ source('apple_store', 'usage_platform_version_source_type_report') }}"
usage_territory: "{{ source('apple_store', 'usage_territory_source_type_report') }}"
apple_store_country_codes: "{{ ref('apple_store_country_codes') }}"
apple_store__subscription_events:
- 'Renew'
Expand Down
2 changes: 1 addition & 1 deletion docs/catalog.json

Large diffs are not rendered by default.

Loading

0 comments on commit fce24ad

Please sign in to comment.