Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Add batching when uploading models #344

Merged
merged 2 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions macros/upload_models.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{% macro upload_models(graph) -%}
{% set models = [] %}
{% for node in graph.nodes.values() | selectattr("resource_type", "equalto", "model") %}
{% do models.append(node) %}
{% endfor %}
{% macro upload_models(models) -%}
{{ return(adapter.dispatch('get_models_dml_sql', 'dbt_artifacts')(models)) }}
{%- endmacro %}

Expand Down
24 changes: 15 additions & 9 deletions macros/upload_results.sql
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
{% endfor %}
{# upload tests in chunks of 5000 tests (750 for BigQuery), or less #}
{% set upload_limit = 750 if target.type == 'bigquery' else 5000 %}
{% set n = (tests_set|length/upload_limit)|round(0, 'ceil')|int %}
{% for i in range(0, tests_set | length, upload_limit) -%}
{% set content_tests = dbt_artifacts.upload_tests(tests_set[i: i + upload_limit]) %}
{{ dbt_artifacts.insert_into_metadata_table(
Expand All @@ -109,14 +108,21 @@

{% do log("Uploading models", true) %}
{% set models = dbt_artifacts.get_relation('models') %}
{% set content_models = dbt_artifacts.upload_models(graph) %}
{{ dbt_artifacts.insert_into_metadata_table(
database_name=models.database,
schema_name=models.schema,
table_name=models.identifier,
content=content_models
)
}}
{% set models_set = [] %}
{% for node in graph.nodes.values() | selectattr("resource_type", "equalto", "model") %}
{% do models_set.append(node) %}
{% endfor %}
{% set upload_limit = 50 if target.type == 'bigquery' else 100 %}
{% for i in range(0, models_set | length, upload_limit) -%}
{% set content_models = dbt_artifacts.upload_models(models_set[i: i + upload_limit]) %}
{{ dbt_artifacts.insert_into_metadata_table(
database_name=models.database,
schema_name=models.schema,
table_name=models.identifier,
content=content_models
)
}}
{%- endfor %}

{% do log("Uploading sources", true) %}
{% set sources = dbt_artifacts.get_relation('sources') %}
Expand Down