-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: 升级dbt版本到 1.9,并支持新的增量物化策略 (#5)
- Loading branch information
1 parent
3ff913c
commit 60faed5
Showing
11 changed files
with
327 additions
and
49 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version = "1.8.0-alpha.13" | ||
version = "1.9.0-alpha" |
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
87 changes: 87 additions & 0 deletions
87
...xcompute/macros/materializations/incremental/bq_incremental_strategy/insert_overwrite.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,87 @@ | ||
{% macro mc_generate_incremental_insert_overwrite_build_sql( | ||
tmp_relation, target_relation, sql, unique_key, partition_by, partitions, dest_columns, tmp_relation_exists | ||
) %} | ||
{% if partition_by is none %} | ||
{% set missing_partition_msg -%} | ||
The 'bq_insert_overwrite' strategy requires the `partition_by` config. | ||
{%- endset %} | ||
{% do exceptions.raise_compiler_error(missing_partition_msg) %} | ||
{% endif %} | ||
|
||
{% if partition_by.fields|length != 1 %} | ||
{% set missing_partition_msg -%} | ||
The 'bq_insert_overwrite' strategy requires the `partition_by` config. | ||
{%- endset %} | ||
{% do exceptions.raise_compiler_error(missing_partition_msg) %} | ||
{% endif %} | ||
|
||
{% set build_sql = mc_insert_overwrite_sql( | ||
tmp_relation, target_relation, sql, unique_key, partition_by, partitions, dest_columns, tmp_relation_exists | ||
) %} | ||
|
||
{{ return(build_sql) }} | ||
|
||
{% endmacro %} | ||
|
||
{% macro mc_insert_overwrite_sql( | ||
tmp_relation, target_relation, sql, unique_key, partition_by, partitions, dest_columns, tmp_relation_exists | ||
) %} | ||
{% if partitions is not none and partitions != [] %} {# static #} | ||
{{ mc_static_insert_overwrite_sql(tmp_relation, target_relation, sql, partition_by, partitions, dest_columns, tmp_relation_exists) }} | ||
{% else %} {# dynamic #} | ||
{{ mc_dynamic_insert_overwrite_sql(tmp_relation, target_relation, sql, unique_key, partition_by, dest_columns, tmp_relation_exists) }} | ||
{% endif %} | ||
{% endmacro %} | ||
|
||
{% macro mc_static_insert_overwrite_sql( | ||
tmp_relation, target_relation, sql, partition_by, partitions, dest_columns, tmp_relation_exists | ||
) %} | ||
|
||
{% set predicate -%} | ||
{{ partition_by.render(False) }} in ({{ partitions | join (', ') }}) | ||
{%- endset %} | ||
|
||
{%- set source_sql -%} | ||
( | ||
{% if tmp_relation_exists -%} | ||
select * from {{ tmp_relation }} | ||
{%- else -%} | ||
{{sql}} | ||
{%- endif %} | ||
) | ||
{%- endset -%} | ||
|
||
{%- call statement('main') -%} | ||
{{ get_insert_overwrite_merge_sql(target_relation, source_sql, dest_columns, [predicate], include_sql_header = not tmp_relation_exists) }}; | ||
{%- endcall -%} | ||
|
||
{%- if tmp_relation_exists -%} | ||
-- 2. clean up the temp table | ||
drop table if exists {{ tmp_relation }}; | ||
{%- endif -%} | ||
{% endmacro %} | ||
|
||
{% macro mc_dynamic_insert_overwrite_sql(tmp_relation, target_relation, sql, unique_key, partition_by, dest_columns, tmp_relation_exists) %} | ||
{% set predicate -%} | ||
{{partition_by.render(False)}} in (select distinct {{partition_by.render(False)}} from {{ tmp_relation }}) | ||
{%- endset %} | ||
|
||
{%- set source_sql -%} | ||
( | ||
select * from {{ tmp_relation }} | ||
) | ||
{%- endset -%} | ||
{% if not tmp_relation_exists %} | ||
{%- call statement('create_tmp_relation') -%} | ||
{{ create_table_as_internal(True, tmp_relation, sql, True, partition_config=partition_by) }} | ||
{%- endcall -%} | ||
{% else %} | ||
-- 1. temp table already exists, we used it to check for schema changes | ||
{% endif %} | ||
-- 3. run the merge statement | ||
{%- call statement('main') -%} | ||
{{ get_insert_overwrite_merge_sql(target_relation, source_sql, dest_columns, [predicate]) }}; | ||
{%- endcall -%} | ||
-- 4. clean up the temp table | ||
drop table if exists {{ tmp_relation }} | ||
{% endmacro %} |
28 changes: 28 additions & 0 deletions
28
...ude/maxcompute/macros/materializations/incremental/bq_incremental_strategy/microbatch.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,28 @@ | ||
{% macro mc_validate_microbatch_config(config) %} | ||
{% if config.get("partition_by") is none %} | ||
{% set missing_partition_msg -%} | ||
The 'microbatch' strategy requires a `partition_by` config. | ||
{%- endset %} | ||
{% do exceptions.raise_compiler_error(missing_partition_msg) %} | ||
{% endif %} | ||
|
||
{% if config.get("partition_by").granularity != config.get('batch_size') %} | ||
{% set invalid_partition_by_granularity_msg -%} | ||
The 'microbatch' strategy requires a `partition_by` config with the same granularity as its configured `batch_size`. | ||
Got: | ||
`batch_size`: {{ config.get('batch_size') }} | ||
`partition_by.granularity`: {{ config.get("partition_by").granularity }} | ||
{%- endset %} | ||
{% do exceptions.raise_compiler_error(invalid_partition_by_granularity_msg) %} | ||
{% endif %} | ||
{% endmacro %} | ||
|
||
{% macro mc_generate_microbatch_build_sql( | ||
tmp_relation, target_relation, sql, unique_key, partition_by, partitions, dest_columns, tmp_relation_exists | ||
) %} | ||
{% set build_sql = mc_insert_overwrite_sql( | ||
tmp_relation, target_relation, sql, unique_key, partition_by, partitions, dest_columns, tmp_relation_exists | ||
) %} | ||
|
||
{{ return(build_sql) }} | ||
{% endmacro %} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% materialization raw, adapter='maxcompute' -%} | ||
{% call statement("main") %} | ||
{{ sql }} | ||
{% endcall %} | ||
{{ return({'relations': []}) }} | ||
{%- endmaterialization %} |
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
Oops, something went wrong.