Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/update passthrough coulmns #38

Merged
merged 14 commits into from
May 4, 2023
3 changes: 2 additions & 1 deletion .buildkite/scripts/run_models.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ dbt seed --target "$db" --full-refresh
dbt run --target "$db" --full-refresh
dbt test --target "$db"
dbt run --vars '{using_account_history_mode_active_records: true, using_opportunity_history_mode_active_records: true, using_user_role_history_mode_active_records: true, using_user_history_mode_active_records: true, salesforce__user_role_enabled: false}' --target "$db" --full-refresh
dbt test --target "$db"
dbt test --target "$db"
dbt run-operation fivetran_utils.drop_schemas_automation --target "$db"
51 changes: 51 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/maintainer_pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
## PR Overview
**This PR will address the following Issue/Feature:**

**This PR will result in the following new package version:**
<!--- Please add details around your decision for breaking vs non-breaking version upgrade. If this is a breaking change, were backwards-compatible options explored? -->

**Please detail what change(s) this PR introduces and any additional information that should be known during the review of this PR:**

## PR Checklist
### Basic Validation
Please acknowledge that you have successfully performed the following commands locally:
- [ ] dbt compile
- [ ] dbt run –full-refresh
- [ ] dbt run
- [ ] dbt test
- [ ] dbt run –vars (if applicable)

Before marking this PR as "ready for review" the following have been applied:
- [ ] The appropriate issue has been linked and tagged
- [ ] You are assigned to the corresponding issue and this PR
- [ ] BuildKite integration tests are passing

### Detailed Validation
Please acknowledge that the following validation checks have been performed prior to marking this PR as "ready for review":
- [ ] You have validated these changes and assure this PR will address the respective Issue/Feature.
- [ ] You are reasonably confident these changes will not impact any other components of this package or any dependent packages.
- [ ] You have provided details below around the validation steps performed to gain confidence in these changes.
<!--- Provide the steps you took to validate your changes below. -->

### Standard Updates
Please acknowledge that your PR contains the following standard updates:
- Package versioning has been appropriately indexed in the following locations:
- [ ] indexed within dbt_project.yml
- [ ] indexed within integration_tests/dbt_project.yml
- [ ] CHANGELOG has individual entries for each respective change in this PR
<!--- If there is a parallel upstream change, remember to reference the corresponding CHANGELOG as an individual entry. -->
- [ ] README updates have been applied (if applicable)
<!--- Remember to check the following README locations for common updates. →
<!--- Suggested install range (needed for breaking changes) →
<!--- Dependency matrix is appropriately updated (if applicable) →
<!--- New variable documentation (if applicable) -->
- [ ] DECISIONLOG updates have been updated (if applicable)
- [ ] Appropriate yml documentation has been added (if applicable)

### dbt Docs
Please acknowledge that after the above were all completed the below were applied to your branch:
- [ ] docs were regenerated (unless this PR does not include any code or yml updates)

### If you had to summarize this PR in an emoji, which would it be?
<!--- For a complete list of markdown compatible emojis check our this git repo (https://gist.github.com/rxaviers/7360908) -->
:dancer:
51 changes: 16 additions & 35 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,33 @@
**Are you a current Fivetran customer?**
<!--- Please tell us your name, title and company -->
**Please provide your name and company**

**What change(s) does this PR introduce?**
<!--- Describe what changes your PR introduces to the package and how to leverage this new feature. -->
**Link the issue/feature request which this PR is meant to address**
<!--- If an issue was not created, please create one first so we may discuss the PR prior to opening one. -->

**Did you update the CHANGELOG?**
**Detail what changes this PR introduces and how this addresses the issue/feature request linked above.**

**How did you validate the changes introduced within this PR?**

**Which warehouse did you use to develop these changes?**

**Did you update the CHANGELOG?**
<!--- Please update the new package version’s CHANGELOG entry detailing the changes included in this PR. -->
<!--- To select a checkbox you simply need to add an "x" with no spaces between the brackets (eg. [x] Yes). -->
- [ ] Yes

**Does this PR introduce a breaking change?**
<!--- Does this PR introduce changes that will cause current package users' jobs to fail or require a `--full-refresh`? -->
<!--- To select a checkbox you simply need to add an "x" with no spaces between the brackets (eg. [x] Yes). -->
- [ ] Yes (please provide breaking change details below.)
- [ ] No (please provide an explanation as to how the change is non-breaking below.)

**Did you update the dbt_project.yml files with the version upgrade (please leverage standard semantic versioning)? (In both your main project and integration_tests)**
**Did you update the dbt_project.yml files with the version upgrade (please leverage standard semantic versioning)? (In both your main project and integration_tests)**
<!--- The dbt_project.yml and the integration_tests/dbt_project.yml files contain the version number. Be sure to upgrade it accordingly -->
<!--- To select a checkbox you simply need to add an "x" with no spaces between the brackets (eg. [x] Yes). -->
- [ ] Yes

**Is this PR in response to a previously created Bug or Feature Request**
<!--- If an Issue was created it is helpful to track the progress by linking it in the PR. -->
<!--- To select a checkbox you simply need to add an "x" with no spaces between the brackets (eg. [x] Yes). -->
- [ ] Yes, Issue/Feature [link bug/feature number here]
- [ ] No

**How did you test the PR changes?**
<!--- Proof of testing is required in order for the PR to be approved. -->
<!--- To check a box, remove the space and insert an x in the box (eg. [x] Buildkite). -->
<!--- To select a checkbox you simply need to add an "x" with no spaces between the brackets (eg. [x] Yes). -->
- [ ] Buildkite <!--- Buildkite testing is only applicable to Fivetran employees. -->
- [ ] Local (please provide additional testing details below)

**Select which warehouse(s) were used to test the PR**
<!--- To check a warehouse remove the space and insert an x in the box (eg. [x] Bigquery). -->
<!--- To select a checkbox you simply need to add an "x" with no spaces between the brackets (eg. [x] Yes). -->
- [ ] BigQuery
- [ ] Redshift
- [ ] Snowflake
- [ ] Postgres
- [ ] Databricks
- [ ] Other (provide details below)

**Provide an emoji that best describes your current mood**
<!--- For a complete list of markdown compatible emojis check our this git repo (https://gist.github.com/rxaviers/7360908) -->
:dancer:

**Feedback**

We are so excited you decided to contribute to the Fivetran community dbt package! We continue to work to improve the packages and would greatly appreciate your [feedback](https://www.surveymonkey.com/r/DQ7K7WW) on our existing dbt packages or what you'd like to see next.

**PR Template**
- [Community Pull Request Template](?expand=1&template=pull_request_template.md) (default)

- [Maintainer Pull Request Template](?expand=1&template=maintainer_pull_request_template.md) (to be used by maintainers)
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
<<<<<<< HEAD
# dbt_salesforce v0.9.0

## 🚨 Breaking Changes 🚨:
[PR #38](https://github.com/fivetran/dbt_salesforce/pull/38) includes the following breaking changes:

- Updates the old passthrough column methodology to allow for aliasing of any field names brought in. This is useful, for example, if you wish to bring in fields across different Salesforce objects that may have the same names and wish to alias them to avoid confusion, particularly if any of the objects are joined together.

- Additionally, in the `salesforce__opportunity_enhanced` model, the old `opportunity_enhanced_pass_through_columns` variable has been replaced with the existing variables from the staging models (see below). This is because we updated the `salesforce__opportunity_enhanced` model with regards to how custom fields passed through from the `user` table are dealt with. Since the `user` model is joined in two times, once as information about an opportunity owner and the other about an opportunity manager, to avoid ambiguity, custom fields passed through from the user table will be suffixed based on whether it belongs to a user who is an `_owner` or a `_manager`.

- Finally, we have added the `salesforce__` prefix to all the passthrough variables:

|**Old**|**New**
-----|-----
| account_pass_through_columns | salesforce__account_pass_through_columns
| contact_pass_through_columns | salesforce__contact_pass_through_columns
| event_pass_through_columns | salesforce__event_pass_through_columns
| lead_pass_through_columns | salesforce__lead_pass_through_columns
| opportunity_pass_through_columns | salesforce__opportunity_pass_through_columns
| opportunity_line_item_pass_through_columns | salesforce__opportunity_line_item_pass_through_columns
| order_pass_through_columns | salesforce__order_pass_through_columns
| product_2_pass_through_columns | salesforce__product_2_pass_through_columns
| task_pass_through_columns | salesforce__task_pass_through_columns
| user_role_pass_through_columns | salesforce__user_role_pass_through_columns
| user_pass_through_columns | salesforce__user_pass_through_columns


=======
# dbt_salesforce v0.UPDATE.UPDATE

## Under the Hood:

- Incorporated the new `fivetran_utils.drop_schemas_automation` macro into the end of each Buildkite integration test job.
- Updated the pull request [templates](/.github).
>>>>>>> remotes/origin/MagicBot/integation-test-webhooks-14
# dbt_salesforce v0.8.0

## 🚨 Breaking Changes 🚨:
Expand Down
60 changes: 43 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Include the following salesforce package version in your `packages.yml`
```yaml
packages:
- package: fivetran/salesforce
version: [">=0.8.0", "<0.9.0"]
version: [">=0.9.0", "<0.10.0"]
```
## Step 3: Configure Your Variables
### Database and Schema Variables
Expand Down Expand Up @@ -121,24 +121,48 @@ models:
+schema: my_new_schema_name # leave blank for just the target_schema
```
### Adding Passthrough Columns
This package allows users to add additional columns to the `opportunity enhanced` model and `contact enhanced` model by using the below variables in you `dbt_project.yml` file. For the `opportunity enhanced` model, columns passed through in `opportunity_enhanced_pass_through_columns` must also be present in the upstream source `opportunity`, `account`, `user`, or `user_role` table. If you want to include a column from the `user` table, you must specify if you want it to be a field related to the opportunity_manager or opportunity_owner.
This package allows users to add additional columns to the `salesforce__opportunity_enhanced`, `salesforce__opportunity_line_item_enhanced`, and `salesforce__contact_enhanced` model by using the below variables in your `dbt_project.yml` file.

For the `salesforce__opportunity_enhanced` model, it joins in the `user` model two times, since an opportunity has both an owner and manager. The first time the `user` model is joined is to add information about an opportunity owner. The second time is to add information about an opportunity manager. Therefore to avoid ambiguous columns from joining in the same model twice, custom fields passed through from the user table will be suffixed based on whether it belongs to a user who is an `_owner` or a `_manager`.

Additionally, you may add additional columns to the staging models. For example, for passing columns to `stg_salesforce__product_2` you would need to configure `product_2_pass_through_columns`.
Additionally, you may add additional columns to the staging models. For example, for passing columns to `stg_salesforce__product_2` you would need to configure `salesforce__product_2_pass_through_columns`.

```yml
vars:
opportunity_enhanced_pass_through_columns: [account_custom_field_1, my_opp_custom_field, user_role_custom_field_1, opportunity_manager.user_custom_column_1]
account_pass_through_columns: [account_custom_field_1, account_custom_field_2]
user_pass_through_columns: [user_custom_column_1,user_custom_column_2]
contact_pass_through_columns: [contact_custom_field_1, contact_custom_field_2]
opportunity_pass_through_columns: [my_opp_custom_field]
lead_pass_through_columns: [lead_custom_field_1, lead_custom_field_2]
task_pass_through_columns: [task_custom_field_1, task_custom_field_2]
event_pass_through_columns: [event_custom_field_1, event_custom_field_2]
product_2_pass_through_columns: [product_2_custom_field_1, product_2_custom_field_2]
order_pass_through_columns: [order_custom_field_1, order_custom_field_2]
opportunity_line_item_pass_through_columns: [opportunity_line_item_custom_field_1, opportunity_line_item_custom_field_2]
user_role_pass_through_columns: [user_role_custom_field_1, user_role_custom_field_2]
salesforce__account_pass_through_columns:
- name: "salesforce__account_field"
alias: "salesforce__account_field"
salesforce__contact_pass_through_columns:
- name: "salesforce__contact_field"
alias: "contact_field_x"
salesforce__event_pass_through_columns:
- name: "salesforce__event_field"
salesforce__lead_pass_through_columns:
- name: "salesforce__lead_field"
salesforce__opportunity_pass_through_columns:
- name: "salesforce__opportunity_field"
alias: "opportunity_field_x"
salesforce__opportunity_line_item_pass_through_columns:
- name: "salesforce__opportunity_line_item_field"
alias: "opportunity_line_item_field_x"
- name: "field_name_2"
salesforce__order_pass_through_columns:
- name: "salesforce__order_field"
alias: "order_field_x"
- name: "another_field"
alias: "field_abc"
salesforce__product_2_pass_through_columns:
- name: "salesforce__product_2_field"
alias: "product_2_field_x"
salesforce__task_pass_through_columns:
- name: "salesforce__task_field"
alias: "task_field_x"
salesforce__user_role_pass_through_columns:
- name: "salesforce__user_role_field"
alias: "user_role_field_x"
salesforce__user_pass_through_columns:
- name: "salesforce__user_field"

```

## (Optional) Step 5: Adding Formula Fields as Pass Through Columns
Expand All @@ -159,7 +183,9 @@ Include the following within your `dbt_project.yml` file:
opportunity: "{{ ref('my_opportunity_formula_table') }}"

# In addition, add the desired field names as pass through columns
opportunity_pass_through_columns: ['formula_field_1','formula_field_2']
salesforce__opportunity_pass_through_columns:
- name: "salesforce__opportunity_field"
alias: "opportunity_field_x"
```

## (Optional) Step 6: Orchestrate your models with Fivetran Transformations for dbt Core™
Expand All @@ -171,7 +197,7 @@ This dbt package is dependent on the following dbt packages. For more informatio
```yml
packages:
- package: fivetran/salesforce_source
version: [">=0.6.0", "<0.7.0"]
version: [">=0.7.0", "<0.8.0"]
fivetran-joemarkiewicz marked this conversation as resolved.
Show resolved Hide resolved
- package: fivetran/fivetran_utils
version: [">=0.4.0", "<0.5.0"]
- package: dbt-labs/dbt_utils
Expand Down
27 changes: 14 additions & 13 deletions dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
config-version: 2
name: 'salesforce'
version: '0.8.0'
version: '0.9.0'
require-dbt-version: [">=1.3.0", "<2.0.0"]
models:
salesforce:
Expand All @@ -20,18 +20,19 @@ vars:
product_2: "{{ ref('stg_salesforce__product_2') }}"
order: "{{ ref('stg_salesforce__order') }}"
opportunity_line_item: "{{ ref('stg_salesforce__opportunity_line_item') }}"
opportunity_enhanced_pass_through_columns: []
account_pass_through_columns: []
contact_pass_through_columns: []
event_pass_through_columns: []
lead_pass_through_columns: []
opportunity_pass_through_columns: []
opportunity_line_item_pass_through_columns: []
order_pass_through_columns: []
product_2_pass_through_columns: []
task_pass_through_columns: []
user_role_pass_through_columns: []
user_pass_through_columns: []

salesforce__account_pass_through_columns: []
salesforce__contact_pass_through_columns: []
salesforce__event_pass_through_columns: []
salesforce__lead_pass_through_columns: []
salesforce__opportunity_pass_through_columns: []
salesforce__opportunity_line_item_pass_through_columns: []
salesforce__order_pass_through_columns: []
salesforce__product_2_pass_through_columns: []
salesforce__task_pass_through_columns: []
salesforce__user_role_pass_through_columns: []
salesforce__user_pass_through_columns: []

clean-targets:
- target
- dbt_modules
Expand Down
2 changes: 1 addition & 1 deletion docs/catalog.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 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.

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

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions integration_tests/ci/sample.profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ integration_tests:
pass: "{{ env_var('CI_REDSHIFT_DBT_PASS') }}"
dbname: "{{ env_var('CI_REDSHIFT_DBT_DBNAME') }}"
port: 5439
schema: salesforce_integrations_tests
schema: salesforce_integrations_tests_1
threads: 8
bigquery:
type: bigquery
method: service-account-json
project: 'dbt-package-testing'
schema: salesforce_integrations_tests
schema: salesforce_integrations_tests_1
threads: 8
keyfile_json: "{{ env_var('GCLOUD_SERVICE_KEY') | as_native }}"
snowflake:
Expand All @@ -33,7 +33,7 @@ integration_tests:
role: "{{ env_var('CI_SNOWFLAKE_DBT_ROLE') }}"
database: "{{ env_var('CI_SNOWFLAKE_DBT_DATABASE') }}"
warehouse: "{{ env_var('CI_SNOWFLAKE_DBT_WAREHOUSE') }}"
schema: salesforce_integrations_tests
schema: salesforce_integrations_tests_1
threads: 8
postgres:
type: postgres
Expand All @@ -42,13 +42,13 @@ integration_tests:
pass: "{{ env_var('CI_POSTGRES_DBT_PASS') }}"
dbname: "{{ env_var('CI_POSTGRES_DBT_DBNAME') }}"
port: 5432
schema: salesforce_integrations_tests
schema: salesforce_integrations_tests_1
threads: 8
databricks:
catalog: null
host: "{{ env_var('CI_DATABRICKS_DBT_HOST') }}"
http_path: "{{ env_var('CI_DATABRICKS_DBT_HTTP_PATH') }}"
schema: salesforce_integrations_tests
schema: salesforce_integrations_tests_1
threads: 2
token: "{{ env_var('CI_DATABRICKS_DBT_TOKEN') }}"
type: databricks
4 changes: 2 additions & 2 deletions integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'salesforce_integration_tests'
version: '0.8.0'
version: '0.9.0'
config-version: 2

profile: 'integration_tests'
Expand All @@ -23,7 +23,7 @@ vars:
salesforce_product_2_identifier: "sf_product_2_data"
salesforce_order_identifier: "sf_order_data"
salesforce_opportunity_line_item_identifier: "sf_opportunity_line_item_data"
salesforce_schema: salesforce_integrations_tests
salesforce_schema: salesforce_integrations_tests_1

seeds:
salesforce_integration_tests:
Expand Down
9 changes: 9 additions & 0 deletions macros/custom_persist_pass_through_columns.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% macro custom_persist_pass_through_columns(pass_through_variable, identifier=none, transform='', append_string='') %}

{% if var(pass_through_variable, none) %}
{% for field in var(pass_through_variable) %}
, {{ transform ~ '(' ~ (identifier ~ '.' if identifier else '') ~ (field.alias if field.alias else field.name) ~ ')' }} as {{ field.alias if field.alias else field.name }}{{ append_string }}
{% endfor %}
{% endif %}

{% endmacro %}
Loading