From ab40b89535f463cc4a58e8bf392f7bd27b651f18 Mon Sep 17 00:00:00 2001 From: Quigley Malcolm Date: Wed, 20 Nov 2024 12:01:23 -0600 Subject: [PATCH] Append the `model.batch.id` to the temporary relation suffix when available --- dbt/include/global_project/macros/adapters/relation.sql | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dbt/include/global_project/macros/adapters/relation.sql b/dbt/include/global_project/macros/adapters/relation.sql index b9af4969..ae1f041d 100644 --- a/dbt/include/global_project/macros/adapters/relation.sql +++ b/dbt/include/global_project/macros/adapters/relation.sql @@ -7,6 +7,11 @@ {% endmacro %} {% macro make_temp_relation(base_relation, suffix='__dbt_tmp') %} + {#-- This ensures microbatch batches get unique temp relations to avoid clobbering --#} + {% if suffix == '__dbt_tmp' and model.batch %} + {% set suffix = suffix ~ '_' ~ model.batch.id %} + {% endif %} + {{ return(adapter.dispatch('make_temp_relation', 'dbt')(base_relation, suffix)) }} {% endmacro %}