Skip to content

Commit

Permalink
Merge pull request #353 from elementary-data/ele-858-created-edr_make…
Browse files Browse the repository at this point in the history
…_session_temp_relation

Created 'edr_make_session_temp_relation'.
  • Loading branch information
elongl authored May 14, 2023
2 parents 133ed73 + 5d3f6a3 commit bcb3560
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions macros/edr/tests/on_run_end/handle_tests_results.sql
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
{% if not target_relation %}
{% do exceptions.raise_compiler_error("Couldn't find Elementary's models. Please run `dbt run -s elementary`.") %}
{% endif %}
{%- set temp_relation = elementary.edr_make_temp_relation(target_relation) -%}
{%- set temp_relation = elementary.make_temp_view_relation(target_relation) -%}
{%- if test_tables_union_query %}
{{ elementary.file_log('Running union query from test tables to ' ~ temp_relation.identifier) }}
{%- do run_query(dbt.create_table_as(True, temp_relation, test_tables_union_query)) %}
Expand All @@ -84,7 +84,7 @@
{% if not target_relation %}
{% do exceptions.raise_compiler_error("Couldn't find Elementary's models. Please run `dbt run -s elementary`.") %}
{% endif %}
{%- set temp_relation = elementary.edr_make_temp_relation(target_relation) -%}
{%- set temp_relation = elementary.make_temp_view_relation(target_relation) -%}
{%- if test_tables_union_query %}
{{ elementary.file_log('Running union query from test tables to ' ~ temp_relation.identifier) }}
{%- do run_query(dbt.create_table_as(True, temp_relation, test_tables_union_query)) %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
identifier=temp_table_name,
type='table') -%}
{% if is_temp_table %}
{% set temp_table_relation = elementary.edr_make_temp_relation(temp_table_relation) %}
{% set temp_table_relation = elementary.make_temp_view_relation(temp_table_relation) %}
{% endif %}

{# Cache the test table for easy access later #}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% macro create_intermediate_relation(base_relation, rows, temporary, like_columns=none) %}
{% set int_relation = elementary.edr_make_temp_relation(base_relation).incorporate(type='table') %}
{% set int_relation = elementary.make_temp_table_relation(base_relation).incorporate(type='table') %}

{% if not elementary.has_temp_table_support() %}
{% set temporary = false %}
Expand Down
16 changes: 12 additions & 4 deletions macros/utils/table_operations/make_temp_relation.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
{% macro edr_make_temp_relation(base_relation, suffix=none) %}
{% macro make_temp_view_relation(base_relation, suffix=none) %}
{% if not suffix %}
{% set suffix = modules.datetime.datetime.utcnow().strftime('__tmp_%Y%m%d%H%M%S%f') %}
{% endif %}

{% do return(adapter.dispatch("edr_make_temp_relation", "elementary")(base_relation, suffix)) %}
{% do return(dbt.make_temp_relation(base_relation, suffix)) %}
{% endmacro %}

{% macro make_temp_table_relation(base_relation, suffix=none) %}
{% if not suffix %}
{% set suffix = modules.datetime.datetime.utcnow().strftime('__tmp_%Y%m%d%H%M%S%f') %}
{% endif %}

{% do return(adapter.dispatch("make_temp_table_relation", "elementary")(base_relation, suffix)) %}
{% endmacro %}

{% macro default__edr_make_temp_relation(base_relation, suffix) %}
{% macro default__make_temp_table_relation(base_relation, suffix) %}
{% do return(dbt.make_temp_relation(base_relation, suffix)) %}
{% endmacro %}

{% macro databricks__edr_make_temp_relation(base_relation, suffix) %}
{% macro databricks__make_temp_table_relation(base_relation, suffix) %}
{% set tmp_identifier = base_relation.identifier ~ suffix %}
{% set tmp_relation = api.Relation.create(
identifier=tmp_identifier,
Expand Down

0 comments on commit bcb3560

Please sign in to comment.