Skip to content

Commit

Permalink
adding config option for table and incremental materializaions
Browse files Browse the repository at this point in the history
  • Loading branch information
gregology committed Jul 31, 2024
1 parent 8c0a192 commit 49416c9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dbt/include/bigquery/macros/materializations/incremental.sql
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@

{{ run_hooks(pre_hooks) }}

{{ bigquery__run_script_headers(config.get('script_headers')) }}

{% if partition_by.copy_partitions is true and strategy != 'insert_overwrite' %} {#-- We can't copy partitions with merge strategy --#}
{% set wrong_strategy_msg -%}
The 'copy_partitions' option requires the 'incremental_strategy' option to be set to 'insert_overwrite'.
Expand Down
2 changes: 2 additions & 0 deletions dbt/include/bigquery/macros/materializations/table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

{{ run_hooks(pre_hooks) }}

{{ bigquery__run_script_headers(config.get('script_headers')) }}

{#
We only need to drop this thing if it is not a table.
If it _is_ already a table, then we can overwrite it without downtime
Expand Down
21 changes: 21 additions & 0 deletions dbt/include/bigquery/macros/utils/run_script_headers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% macro bigquery__run_script_headers(script_headers) %}
{%- if script_headers is not none -%}
{%- if script_headers is string -%}
{%- set script_headers = [script_headers] -%}
{%- endif -%}

{%- set formatted_script_headers = [] -%}

{%- for script_header in script_headers -%}
{%- set trimmed_script_header = script_header.strip() -%}
{%- if not trimmed_script_header.endswith(';') -%}
{%- set formatted_script_header = trimmed_script_header ~ ';' -%}
{%- else -%}
{%- set formatted_script_header = trimmed_script_header -%}
{%- endif -%}
{%- do formatted_script_headers.append(formatted_script_header) -%}
{%- endfor -%}

{{ formatted_script_headers | join('\n') }}
{%- endif -%}
{%- endmacro -%}

0 comments on commit 49416c9

Please sign in to comment.