Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
34e037d
first draft
Jan 24, 2024
21b1131
style fixes by ruff
sungchun12 Jan 24, 2024
a7b575d
past tense consistency
Jan 24, 2024
ce9c743
working draft of new table
Jan 24, 2024
8925474
style fixes by ruff
sungchun12 Jan 24, 2024
5e9b55d
dbt diffs work, cloud broken for now
Jan 24, 2024
ff99881
remove cached git repos
Jan 24, 2024
8e79b92
efficient naming
Jan 24, 2024
b84fa26
add type changed count
Jan 24, 2024
e222316
reorder for priority on prod changes
Jan 24, 2024
47e4b0e
tabulate value diffs
Jan 24, 2024
9e89281
style fixes by ruff
sungchun12 Jan 24, 2024
2d3398e
less horizontal space needed
Jan 24, 2024
52949d4
leo's feedback
Jan 25, 2024
6d1d265
center align values
Jan 25, 2024
3f23314
consistent formatting
Jan 25, 2024
887ff7e
shorter name same meaning
Jan 25, 2024
076d0e2
row counts and diff values working
Jan 25, 2024
c6157b3
deps impacts works now
Jan 25, 2024
4cff08f
default val
Jan 25, 2024
4c65ceb
more readable
Jan 25, 2024
1c246ce
add primary key used
Jan 26, 2024
9154995
add model specific CI configs
Jan 26, 2024
0afe71c
consistency
Jan 26, 2024
026b4be
conditional headers
Jan 26, 2024
e880caf
style fixes by ruff
sungchun12 Jan 26, 2024
9e4acb0
cleaner implementation
Jan 29, 2024
e5009db
more cleaning
Jan 29, 2024
99fe5d0
consistent format
Jan 29, 2024
a51cff7
fix unchanged calc
Jan 29, 2024
9d9f53d
remove prints
Jan 29, 2024
7677d1a
default value
Jan 29, 2024
eabe47a
draft up tests
Jan 29, 2024
c5d2f80
a couple more tests
Jan 29, 2024
f52c3a3
new version
Jan 29, 2024
edfbf4f
passing tests
Jan 29, 2024
6134ade
style fixes by ruff
sungchun12 Jan 29, 2024
8e9223d
util unit test
Jan 30, 2024
41dcb27
add unit tests
Jan 30, 2024
99f88da
test the templates
Jan 30, 2024
163b3f2
fix type hints
Jan 30, 2024
a7cb6a5
real test no mocking
Jan 31, 2024
248678f
update tests with all the new outputs
Jan 31, 2024
ecadd5a
add more validations for mock
Jan 31, 2024
fc3f341
fix json bug
Jan 31, 2024
4563beb
Merge branch 'master' into evolve-dbt-output
dlawin Feb 6, 2024
6057923
Merge branch 'master' into evolve-dbt-output
sungchun12 Feb 6, 2024
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
Prev Previous commit
Next Next commit
update tests with all the new outputs
  • Loading branch information
Sung Won Chung committed Jan 31, 2024
commit 248678f7abd6f994e9db2ff9eb6184cae032bed7
Binary file modified tests/dbt_artifacts/jaffle_shop.duckdb
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/dbt_artifacts/target/manifest.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/dbt_artifacts/target/run_results.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"metadata": {"dbt_schema_version": "https://schemas.getdbt.com/dbt/run-results/v4.json", "dbt_version": "1.4.5", "generated_at": "2023-03-28T17:53:00.424212Z", "invocation_id": "289d7789-15b8-44be-a1f6-828f34858212", "env": {}}, "results": [{"status": "success", "timing": [{"name": "compile", "started_at": "2023-03-28T17:53:00.283978Z", "completed_at": "2023-03-28T17:53:00.285641Z"}, {"name": "execute", "started_at": "2023-03-28T17:53:00.285856Z", "completed_at": "2023-03-28T17:53:00.341543Z"}], "thread_id": "Thread-1 (worker)", "execution_time": 0.059603214263916016, "adapter_response": {"_message": "OK"}, "message": "OK", "failures": null, "unique_id": "model.jaffle_shop.stg_customers"}, {"status": "success", "timing": [{"name": "compile", "started_at": "2023-03-28T17:53:00.345114Z", "completed_at": "2023-03-28T17:53:00.346354Z"}, {"name": "execute", "started_at": "2023-03-28T17:53:00.346549Z", "completed_at": "2023-03-28T17:53:00.357085Z"}], "thread_id": "Thread-1 (worker)", "execution_time": 0.013532876968383789, "adapter_response": {"_message": "OK"}, "message": "OK", "failures": null, "unique_id": "model.jaffle_shop.stg_orders"}, {"status": "success", "timing": [{"name": "compile", "started_at": "2023-03-28T17:53:00.359417Z", "completed_at": "2023-03-28T17:53:00.360809Z"}, {"name": "execute", "started_at": "2023-03-28T17:53:00.361018Z", "completed_at": "2023-03-28T17:53:00.371547Z"}], "thread_id": "Thread-1 (worker)", "execution_time": 0.013769149780273438, "adapter_response": {"_message": "OK"}, "message": "OK", "failures": null, "unique_id": "model.jaffle_shop.stg_payments"}, {"status": "success", "timing": [{"name": "compile", "started_at": "2023-03-28T17:53:00.374177Z", "completed_at": "2023-03-28T17:53:00.375799Z"}, {"name": "execute", "started_at": "2023-03-28T17:53:00.376001Z", "completed_at": "2023-03-28T17:53:00.399869Z"}], "thread_id": "Thread-1 (worker)", "execution_time": 0.02851414680480957, "adapter_response": {"_message": "OK"}, "message": "OK", "failures": null, "unique_id": "model.jaffle_shop.customers"}, {"status": "success", "timing": [{"name": "compile", "started_at": "2023-03-28T17:53:00.403579Z", "completed_at": "2023-03-28T17:53:00.405505Z"}, {"name": "execute", "started_at": "2023-03-28T17:53:00.405703Z", "completed_at": "2023-03-28T17:53:00.417432Z"}], "thread_id": "Thread-1 (worker)", "execution_time": 0.01594710350036621, "adapter_response": {"_message": "OK"}, "message": "OK", "failures": null, "unique_id": "model.jaffle_shop.orders"}], "elapsed_time": 0.17573904991149902, "args": {"write_json": true, "use_colors": true, "printer_width": 80, "version_check": true, "partial_parse": true, "static_parser": true, "profiles_dir": "/Users/dan/.dbt", "send_anonymous_usage_stats": true, "quiet": false, "no_print": false, "cache_selected_only": false, "target": "dev", "which": "run", "rpc_method": "run", "indirect_selection": "eager"}}
{"metadata": {"dbt_schema_version": "https://schemas.getdbt.com/dbt/run-results/v5.json", "dbt_version": "1.7.3", "generated_at": "2024-01-31T18:05:26.126216Z", "invocation_id": "baf0db27-f48e-40a3-aa05-1b05b809ec5a", "env": {}}, "results": [{"status": "success", "timing": [{"name": "compile", "started_at": "2024-01-31T18:05:25.960740Z", "completed_at": "2024-01-31T18:05:25.969466Z"}, {"name": "execute", "started_at": "2024-01-31T18:05:25.970040Z", "completed_at": "2024-01-31T18:05:26.040906Z"}], "thread_id": "Thread-1", "execution_time": 0.08749794960021973, "adapter_response": {"_message": "OK"}, "message": "OK", "failures": null, "unique_id": "model.datafold_demo.stg_customers", "compiled": true, "compiled_code": "with source as (\n select * from \"jaffle_shop\".\"dev\".\"raw_customers\"\n\n),\n\nrenamed as (\n\n select\n id as customer_id,\n first_name,\n last_name\n\n from source\n\n)\n\nselect * from renamed", "relation_name": "\"jaffle_shop\".\"dev\".\"stg_customers\""}, {"status": "success", "timing": [{"name": "compile", "started_at": "2024-01-31T18:05:25.967740Z", "completed_at": "2024-01-31T18:05:25.982895Z"}, {"name": "execute", "started_at": "2024-01-31T18:05:25.993495Z", "completed_at": "2024-01-31T18:05:26.048436Z"}], "thread_id": "Thread-3", "execution_time": 0.09017610549926758, "adapter_response": {"_message": "OK"}, "message": "OK", "failures": null, "unique_id": "model.datafold_demo.stg_payments", "compiled": true, "compiled_code": "with source as (\n select * from \"jaffle_shop\".\"dev\".\"raw_payments\"\n\n),\n\nrenamed as (\n\n select\n id as payment_id,\n order_id,\n payment_method,\n\n -- `amount` is currently stored in cents, so we convert it to dollars\n amount / 100 as amount\n\n from source\n\n)\n\nselect * from renamed", "relation_name": "\"jaffle_shop\".\"dev\".\"stg_payments\""}, {"status": "success", "timing": [{"name": "compile", "started_at": "2024-01-31T18:05:25.965435Z", "completed_at": "2024-01-31T18:05:25.976208Z"}, {"name": "execute", "started_at": "2024-01-31T18:05:25.990582Z", "completed_at": "2024-01-31T18:05:26.049746Z"}], "thread_id": "Thread-2", "execution_time": 0.09407401084899902, "adapter_response": {"_message": "OK"}, "message": "OK", "failures": null, "unique_id": "model.datafold_demo.stg_orders", "compiled": true, "compiled_code": "with source as (\n select * from \"jaffle_shop\".\"dev\".\"raw_orders\"\n\n),\n\nrenamed as (\n\n select\n id as order_id,\n user_id as customer_id,\n order_date,\n status\n\n from source\n\n)\n\nselect * from renamed", "relation_name": "\"jaffle_shop\".\"dev\".\"stg_orders\""}, {"status": "success", "timing": [{"name": "compile", "started_at": "2024-01-31T18:05:26.057925Z", "completed_at": "2024-01-31T18:05:26.062891Z"}, {"name": "execute", "started_at": "2024-01-31T18:05:26.064062Z", "completed_at": "2024-01-31T18:05:26.110534Z"}], "thread_id": "Thread-5", "execution_time": 0.05589699745178223, "adapter_response": {"_message": "OK"}, "message": "OK", "failures": null, "unique_id": "model.datafold_demo.customers", "compiled": true, "compiled_code": "with customers as (\n\n select * from \"jaffle_shop\".\"dev\".\"stg_customers\"\n\n),\n\norders as (\n\n select * from \"jaffle_shop\".\"dev\".\"stg_orders\"\n\n),\n\npayments as (\n\n select * from \"jaffle_shop\".\"dev\".\"stg_payments\"\n\n),\n\ncustomer_orders as (\n\n select\n customer_id,\n\n min(order_date) as first_order,\n max(order_date) as most_recent_order,\n count(order_id) as number_of_orders\n from orders\n\n group by customer_id\n\n),\n\ncustomer_payments as (\n\n select\n orders.customer_id,\n sum(amount) as total_amount\n\n from payments\n\n left join orders on\n payments.order_id = orders.order_id\n\n group by orders.customer_id\n\n),\n\nfinal as (\n\n select\n customers.customer_id,\n customers.first_name,\n customers.last_name,\n customer_orders.first_order,\n customer_orders.most_recent_order,\n customer_orders.number_of_orders,\n customer_payments.total_amount as customer_lifetime_value\n\n from customers\n\n left join customer_orders\n on customers.customer_id = customer_orders.customer_id\n\n left join customer_payments\n on customers.customer_id = customer_payments.customer_id\n\n)\n\nselect * from final", "relation_name": "\"jaffle_shop\".\"dev\".\"customers\""}, {"status": "success", "timing": [{"name": "compile", "started_at": "2024-01-31T18:05:26.059981Z", "completed_at": "2024-01-31T18:05:26.063227Z"}, {"name": "execute", "started_at": "2024-01-31T18:05:26.075887Z", "completed_at": "2024-01-31T18:05:26.111336Z"}], "thread_id": "Thread-6", "execution_time": 0.0593719482421875, "adapter_response": {"_message": "OK"}, "message": "OK", "failures": null, "unique_id": "model.datafold_demo.orders", "compiled": true, "compiled_code": "\n\nwith orders as (\n\n select * from \"jaffle_shop\".\"dev\".\"stg_orders\"\n\n),\n\npayments as (\n\n select * from \"jaffle_shop\".\"dev\".\"stg_payments\"\n\n),\n\norder_payments as (\n\n select\n order_id,\n\n sum(case when payment_method = 'credit_card' then amount else 0 end) as credit_card_amount,\n sum(case when payment_method = 'coupon' then amount else 0 end) as coupon_amount,\n sum(case when payment_method = 'bank_transfer' then amount else 0 end) as bank_transfer_amount,\n sum(case when payment_method = 'gift_card' then amount else 0 end) as gift_card_amount,\n sum(amount) as total_amount\n\n from payments\n\n group by order_id\n\n),\n\nfinal as (\n\n select\n orders.order_id+1 as order_id,\n orders.customer_id,\n cast(orders.order_date as varchar) as order_date,\n \n 1 as new_column,\n\n order_payments.credit_card_amount,\n\n order_payments.coupon_amount,\n\n order_payments.bank_transfer_amount,\n\n order_payments.gift_card_amount,\n\n order_payments.total_amount as amount\n\n from orders\n\n\n left join order_payments\n on orders.order_id = order_payments.order_id\n\n),\n\nfinal2 as (\n\n select\n orders.order_id+2 as order_id,\n orders.customer_id,\n cast(orders.order_date as varchar) as order_date,\n \n 1 as new_column,\n\n order_payments.credit_card_amount,\n\n order_payments.coupon_amount,\n\n order_payments.bank_transfer_amount,\n\n order_payments.gift_card_amount,\n\n order_payments.total_amount as amount\n\n from orders\n\n\n left join order_payments\n on orders.order_id = order_payments.order_id\n\n)\n\n(select * from final limit 10)\nunion all\n(select * from final2 where order_id not in (select order_id from final) limit 10)", "relation_name": "\"jaffle_shop\".\"dev\".\"orders\""}], "elapsed_time": 0.23143315315246582, "args": {"log_path": "/Users/sung/Desktop/data-diff/data_diff_demo/logs", "strict_mode": false, "macro_debugging": false, "log_file_max_bytes": 10485760, "warn_error_options": {"include": [], "exclude": []}, "send_anonymous_usage_stats": true, "partial_parse": true, "defer": false, "log_level": "info", "enable_legacy_logger": false, "use_colors_file": true, "cache_selected_only": false, "version_check": true, "vars": {}, "log_level_file": "debug", "exclude": [], "populate_cache": true, "quiet": false, "profiles_dir": "/Users/sung/Desktop/data-diff/data_diff_demo", "which": "run", "favor_state": false, "partial_parse_file_diff": true, "invocation_command": "dbt run", "log_format_file": "debug", "use_colors": true, "indirect_selection": "eager", "project_dir": "/Users/sung/Desktop/data-diff/data_diff_demo", "introspect": true, "select": [], "write_json": true, "printer_width": 80, "show_resource_report": false, "print": true, "log_format": "default", "static_parser": true}}
42 changes: 24 additions & 18 deletions tests/test_dbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,33 @@ def test_integration_basic_dbt(self):
"--dbt", "--dbt-project-dir", test_project_path, "--dbt-profiles-dir", test_profiles_path
)

# assertions for the diff that exists in tests/dbt_artifacts/jaffle_shop.duckdb
orders_expected_output = """
jaffle_shop.prod.orders <> jaffle_shop.dev.orders
Primary Keys: ['order_id']

rows PROD <> DEV
--------- ------ ------------- ------------------
Total 10 20 [+10]
Added +10
Removed 0
Different 0
Unchanged 10
Where Filter: 'amount >= 0'
Included Columns: ['order_id', 'customer_id', 'order_date', 'amount', 'credit_card_amount', 'coupon_amount',
'bank_transfer_amount', 'gift_card_amount']
Excluded Columns: ['new_column']
Columns removed [-1]: {'status'}
Columns added [+1]: {'new_column'}
Type changed [1]: {'order_date'}

rows PROD <> DEV
--------- ------ ------------ -----------------
Total 10 11 [+1]
Added +2
Removed -1
Different 9
Unchanged 0

columns # diff values
-------------------- ---------------
amount 0
bank_transfer_amount 0
coupon_amount 0
credit_card_amount 0
customer_id 0
gift_card_amount 0
order_date 0
status 0
amount 8
bank_transfer_amount 3
coupon_amount 3
credit_card_amount 6
customer_id 9
gift_card_amount 2
"""

stg_payments_expected_output = """
Expand Down Expand Up @@ -123,7 +127,7 @@ def test_integration_motherduck_dbt(self):
assert diff_string.count("PROD") == 1
assert diff_string.count("DEV") == 1
assert diff_string.count("Primary Keys") == 5
assert diff_string.count("Where Filter") == 0
assert diff_string.count("Where Filter") == 1
assert diff_string.count("Type Changed") == 0
assert diff_string.count("Total") == 1
assert diff_string.count("Added") == 1
Expand Down Expand Up @@ -322,6 +326,8 @@ def test_cloud_diff(self, mock_api, mock_os_environ, mock_print):
self.assertEqual(payload.pk_columns, expected_primary_keys)
self.assertEqual(payload.filter1, where)
self.assertEqual(payload.filter2, where)
# TODO: add tests to check the rest of the payload similar to the basic test above
# TODO: add tests to verify TSummaryResultDependencyDetails results

@patch("data_diff.dbt._initialize_api")
@patch("data_diff.dbt._get_diff_vars")
Expand Down