diff --git a/macros/upload_results/insert_into_metadata_table.sql b/macros/upload_results/insert_into_metadata_table.sql index 37994249..2ec4d5d5 100644 --- a/macros/upload_results/insert_into_metadata_table.sql +++ b/macros/upload_results/insert_into_metadata_table.sql @@ -1,15 +1,20 @@ -{% 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 %} @@ -17,10 +22,10 @@ {%- 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 %} @@ -28,10 +33,10 @@ {%- 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 %} @@ -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 %} diff --git a/macros/upload_results/upload_results.sql b/macros/upload_results/upload_results.sql index 5f4df915..fcadc199 100644 --- a/macros/upload_results/upload_results.sql +++ b/macros/upload_results/upload_results.sql @@ -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) %} @@ -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 )