Skip to content

Commit 57a8101

Browse files
authored
Ele 5121 dremio fix for replace table data (#868)
* replace_table_data: bugfix for dremio * get_config_var: disable artifacts caching for dremio * test_artifacts: explicitly set cache_artifacts to True for tests that need it * add comment
1 parent 783928f commit 57a8101

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

integration_tests/tests/test_dbt_artifacts/test_artifacts.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def test_artifacts_caching(dbt_project: DbtProject):
1717
# Disabled by default in the tests for performance reasons.
1818
dbt_project.dbt_runner.vars["disable_dbt_artifacts_autoupload"] = False
1919

20+
dbt_project.dbt_runner.vars["cache_artifacts"] = True
21+
2022
dbt_project.dbt_runner.run(select=TEST_MODEL, vars={"one_tags": ["hello", "world"]})
2123
first_row = read_model_artifact_row(dbt_project)
2224
dbt_project.dbt_runner.run(select=TEST_MODEL, vars={"one_tags": ["world", "hello"]})
@@ -29,6 +31,8 @@ def test_artifacts_updating(dbt_project: DbtProject):
2931
# Disabled by default in the tests for performance reasons.
3032
dbt_project.dbt_runner.vars["disable_dbt_artifacts_autoupload"] = False
3133

34+
dbt_project.dbt_runner.vars["cache_artifacts"] = True
35+
3236
dbt_project.dbt_runner.run(select=TEST_MODEL)
3337
first_row = read_model_artifact_row(dbt_project)
3438
dbt_project.dbt_runner.run(select=TEST_MODEL, vars={"one_owner": "ele"})

macros/edr/system/system_utils/get_config_var.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,12 @@
114114
{%- macro dremio__get_default_config() -%}
115115
{% set default_config = elementary.default__get_default_config() %}
116116
{% do default_config.update({'dbt_artifacts_chunk_size': 100}) %}
117+
118+
{# Caching does work in Dremio, but there is a race between the creation of the temp table
119+
and its usage, and it's causing failures (querying the same table 2 seconds later works).
120+
This is likely a bug in Dremio.
121+
So to be safe we disable caching in Dremio by default. #}
122+
{% do default_config.update({'cache_artifacts': false}) %}
123+
117124
{{- return(default_config) -}}
118125
{%- endmacro -%}

macros/utils/table_operations/replace_table_data.sql

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@
1717

1818
{# Spark - truncate and insert (non-atomic) #}
1919
{% macro spark__replace_table_data(relation, rows) %}
20-
{% call statement('truncate_relation') -%}
20+
{% call statement('truncate_relation') -%}
2121
delete from {{ relation }} where 1=1
22-
{%- endcall %}
22+
{%- endcall %}
23+
{% do elementary.insert_rows(relation, rows, should_commit=false, chunk_size=elementary.get_config_var('dbt_artifacts_chunk_size')) %}
24+
{% endmacro %}
25+
26+
{# Dremio - truncate and insert (non-atomic) #}
27+
{% macro dremio__replace_table_data(relation, rows) %}
28+
{% do dbt.truncate_relation(relation) %}
2329
{% do elementary.insert_rows(relation, rows, should_commit=false, chunk_size=elementary.get_config_var('dbt_artifacts_chunk_size')) %}
2430
{% endmacro %}
2531

0 commit comments

Comments
 (0)