Skip to content

Commit

Permalink
Merge branch 'feat/improve-insert-methods' of github.com:brooklyn-dat…
Browse files Browse the repository at this point in the history
…a/dbt_artifacts into feat/improve-insert-methods
  • Loading branch information
Gemma Down committed Sep 14, 2023
2 parents 54aa3fd + d368961 commit 87660c1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
23 changes: 14 additions & 9 deletions macros/upload_results/insert_into_metadata_table.sql
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
{% macro insert_into_metadata_table(database_name, schema_name, table_name, fields, content) -%}
{% macro insert_into_metadata_table(dataset, fields, content) -%}

{% if content != "" %}
{{ return(adapter.dispatch('insert_into_metadata_table', 'dbt_artifacts')(database_name, schema_name, table_name, fields, content)) }}

{# Get the relation that the results will be uploaded to #}
{% set dataset_relation = dbt_artifacts.get_relation(dataset) %}
{# Insert the data into the table #}
{{ return(adapter.dispatch('insert_into_metadata_table', 'dbt_artifacts')(dataset_relation, fields, content)) }}

{% endif %}

{%- endmacro %}

{% macro spark__insert_into_metadata_table(database_name, schema_name, table_name, fields, content) -%}
{% macro spark__insert_into_metadata_table(relation, fields, content) -%}

{% set insert_into_table_query %}
insert into {% if database_name %}{{ database_name }}.{% endif %}{{ schema_name }}.{{ table_name }} {{ fields }}
insert into {{ relation }} {{ fields }}
{{ content }}
{% endset %}

{% do run_query(insert_into_table_query) %}

{%- endmacro %}

{% macro snowflake__insert_into_metadata_table(database_name, schema_name, table_name, fields, content) -%}
{% macro snowflake__insert_into_metadata_table(relation, fields, content) -%}

{% set insert_into_table_query %}
insert into {{database_name}}.{{ schema_name }}.{{ table_name }} {{ fields }}
insert into {{ relation }} {{ fields }}
{{ content }}
{% endset %}

{% do run_query(insert_into_table_query) %}

{%- endmacro %}

{% macro bigquery__insert_into_metadata_table(database_name, schema_name, table_name, fields, content) -%}
{% macro bigquery__insert_into_metadata_table(relation, fields, content) -%}

{% set insert_into_table_query %}
insert into `{{database_name}}.{{ schema_name }}.{{ table_name }}` {{ fields }}
insert into {{ relation }} {{ fields }}
values
{{ content }}
{% endset %}
Expand All @@ -40,5 +45,5 @@

{%- endmacro %}

{% macro default__insert_into_metadata_table(database_name, schema_name, table_name, fields, content) -%}
{% macro default__insert_into_metadata_table(relation, fields, content) -%}
{%- endmacro %}
7 changes: 1 addition & 6 deletions macros/upload_results/upload_results.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@

{% do log("Uploading " ~ dataset.replace("_", " "), true) %}

{# Get the relation that the results will be uploaded to #}
{% set dataset_relation = dbt_artifacts.get_relation(dataset) %}

{# Get the results that need to be uploaded #}
{% set objects = dbt_artifacts.get_dataset_content(dataset) %}

Expand All @@ -36,9 +33,7 @@

{# Insert the content into the metadata table #}
{{ dbt_artifacts.insert_into_metadata_table(
database_name=dataset_relation.database,
schema_name=dataset_relation.schema,
table_name=dataset_relation.identifier,
dataset=dataset,
fields=dbt_artifacts.get_column_name_list(dataset),
content=content
)
Expand Down

0 comments on commit 87660c1

Please sign in to comment.