Skip to content

Commit 8247332

Browse files
author
Dat Nguyen
committed
feat: add data_diff__auto_pipe
1 parent 277b591 commit 8247332

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

dbt_project.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ vars:
3131
# pipe_name: '' # optional, 1=1 by default
3232
# # in non-async mode, it must be empty if specified
3333
# # in async mode, it can be any value e.g. "1", "batch_dat", "batch_milan"
34+
data_diff__auto_pipe: false # Set true & re-run migration to auto-set `pipe_name` config if it's not specified: Each compared entity will be set in a single thread
3435

3536
on-run-end:
3637
- > # migration hook

macros/resources/refresh_resource_data.sql

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,37 @@
1616
select
1717

1818
{% if source_fixed_naming -%}
19-
'{{ item.get("src_db", target.database) }}' as src_db
20-
,'{{ item.get("src_schema", target.schema) }}' as src_schema
19+
'{{ item.get("src_db", target.database) }}' as src_db
20+
,'{{ item.get("src_schema", target.schema) }}' as src_schema
2121
{%- else -%}
22-
'{{ generate_database_name(item.get("src_db")) }}' as src_db
23-
,'{{ generate_schema_name(item.get("src_schema")) }}' as src_schema
22+
'{{ generate_database_name(item.get("src_db")) }}' as src_db
23+
,'{{ generate_schema_name(item.get("src_schema")) }}' as src_schema
2424
{%- endif -%}
25-
,'{{ item.get("src_table") }}' as src_table
25+
,'{{ item.get("src_table") }}' as src_table
2626

2727
{% if target_fixed_naming -%}
28-
,'{{ item.get("trg_db", target.database) }}' as trg_db
29-
,'{{ item.get("trg_schema", target.schema) }}' as trg_schema
28+
,'{{ item.get("trg_db", target.database) }}' as trg_db
29+
,'{{ item.get("trg_schema", target.schema) }}' as trg_schema
3030
{%- else -%}
31-
,'{{ generate_database_name(item.get("trg_db")) }}' as trg_db
32-
,'{{ generate_schema_name(item.get("trg_schema")) }}' as trg_schema
31+
,'{{ generate_database_name(item.get("trg_db")) }}' as trg_db
32+
,'{{ generate_schema_name(item.get("trg_schema")) }}' as trg_schema
3333
{%- endif -%}
34-
,'{{ item.get("trg_table", item.get("src_table")) }}' as trg_table
35-
36-
,'{{ item.get("pk") }}' as pk
37-
,{{ item.get("include_columns", []) | upper }} as include_columns
38-
,{{ item.get("exclude_columns", []) | upper }} as exclude_columns
39-
,'{{ item.get("where_condition", "1=1") }}' as where_condition
40-
,True as is_enabled
41-
,'{{ item.get("pipe_name", "") }}' as pipe_name --TODO: auto pipe name here?
34+
,'{{ item.get("trg_table", item.get("src_table")) }}' as trg_table
35+
36+
,'{{ item.get("pk") }}' as pk
37+
,{{ item.get("include_columns", []) | upper }} as include_columns
38+
,{{ item.get("exclude_columns", []) | upper }} as exclude_columns
39+
,'{{ item.get("where_condition", "1=1") }}' as where_condition
40+
,True as is_enabled
41+
42+
{% if var("data_diff__auto_pipe", false) -%}
43+
,coalesce(
44+
nullif('{{ item.get("pipe_name", "") }}', ''),
45+
concat(src_db,'.',src_schema,'.',src_table,'-',trg_db,'.',trg_schema,'.',trg_table)
46+
) as pipe_name
47+
{%- else -%}
48+
,'{{ item.get("pipe_name", "") }}' as pipe_name
49+
{%- endif %}
4250

4351
{% if not loop.last -%}
4452
union all

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ data-diff-verify = [
8585
data-diff-migration = [
8686
{cmd = "dbt run -s data_diff --full-refresh --vars '{data_diff__on_migration: true, data_diff__full_refresh: true}' --project-dir integration_tests"},
8787
]
88+
data-diff-migration-auto-pipe = [
89+
{cmd = "dbt run -s data_diff --full-refresh --vars '{data_diff__on_migration: true, data_diff__full_refresh: true, data_diff__auto_pipe: true}' --project-dir integration_tests"},
90+
]
8891
data-diff-bg = [
8992
{cmd = "dbt build -s example --project-dir integration_tests -t blue"},
9093
{cmd = "dbt build -s example --project-dir integration_tests -t green"},

0 commit comments

Comments
 (0)