-
Notifications
You must be signed in to change notification settings - Fork 39
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
Fix divide by zero error #138
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
integration_tests/tests/integrity/deposit_ledger_amounts_match.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
|
||
{{ config( | ||
tags="fivetran_validations", | ||
enabled=var('fivetran_validation_tests_enabled', false) | ||
) }} | ||
|
||
with deposits as ( | ||
|
||
select * | ||
from {{ ref('int_quickbooks__deposit_double_entry') }} | ||
), | ||
|
||
|
||
accounts as ( | ||
|
||
select * | ||
from {{ ref('int_quickbooks__account_classifications') }} | ||
), | ||
|
||
deposits_ledger_source as ( | ||
|
||
select | ||
deposits.transaction_id, | ||
deposits.source_relation, | ||
deposits.index as transaction_index, | ||
deposits.account_id, | ||
deposits.transaction_type, | ||
deposits.transaction_source, | ||
sum(case when accounts.transaction_type = deposits.transaction_type | ||
then deposits.amount | ||
else deposits.amount * -1 end) as adjusted_amount_source, | ||
sum(case when accounts.transaction_type = deposits.transaction_type | ||
then deposits.converted_amount | ||
else deposits.converted_amount * -1 end) as adjusted_converted_amount_source | ||
from deposits | ||
|
||
left join accounts | ||
on deposits.account_id = accounts.account_id | ||
and deposits.source_relation = accounts.source_relation | ||
|
||
group by 1, 2, 3, 4, 5, 6 | ||
), | ||
|
||
deposits_ledger_end as ( | ||
|
||
select | ||
transaction_id, | ||
source_relation, | ||
transaction_index, | ||
account_id, | ||
transaction_type, | ||
transaction_source, | ||
adjusted_amount as adjusted_amount_end, | ||
adjusted_converted_amount as adjusted_converted_amount_end | ||
from {{ ref('quickbooks__general_ledger') }} | ||
where transaction_type = 'deposit' | ||
), | ||
|
||
match_check as ( | ||
|
||
select | ||
deposits_ledger_source.transaction_id, | ||
deposits_ledger_source.source_relation, | ||
deposits_ledger_source.transaction_index, | ||
deposits_ledger_source.account_id, | ||
deposits_ledger_source.transaction_type, | ||
deposits_ledger_source.transaction_source, | ||
deposits_ledger_source.adjusted_amount_source, | ||
deposits_ledger_source.adjusted_converted_amount_source, | ||
deposits_ledger_end.adjusted_amount_end, | ||
deposits_ledger_end.adjusted_converted_amount_end | ||
from deposits_ledger_source | ||
full outer join deposits_ledger_end | ||
on deposits_ledger_source.transaction_id = deposits_ledger_end.transaction_id | ||
and deposits_ledger_source.source_relation = deposits_ledger_end.source_relation | ||
and deposits_ledger_source.transaction_index = deposits_ledger_end.transaction_index | ||
and deposits_ledger_source.account_id = deposits_ledger_end.account_id | ||
and deposits_ledger_source.transaction_type = deposits_ledger_end.transaction_type | ||
and deposits_ledger_source.transaction_source = deposits_ledger_end.transaction_source | ||
) | ||
|
||
select * | ||
from match_check | ||
where abs(adjusted_amount_source - adjusted_amount_end) >= 0.01 | ||
or abs(adjusted_converted_amount_source - adjusted_converted_amount_end) >= 0.01 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also just drop the name of the actual integrity test to make it more straightforward
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed!