microsoft / dbt-fabric

MIT License
79 stars 28 forks source link

fabric__rename_relation - error when re-running model #108

Closed itsalljustdata closed 10 months ago

itsalljustdata commented 11 months ago

When re-running a model (in this case materialising as a view) subsequent to the first time, the code is failing within the "fabric__rename_relation" macro (in include/fabric/macros/adapters/relation.sql) at the sp_rename call. This is because the view already exists. I can get around it by putting pre-hook of

pre_hook = ['USE oracleJM_DW'
           ,'DROP VIEW IF EXISTS bronze.bronze_erp_aging_period_header'
           ] 

for every model, but it's far from ideal!

Incidentally, in my case i'm reading from the lakehouse analytics endpoint and materialising in the DW (if that matters)

for the time being i've got my own copy of the macro that's overriding the default.

{% macro fabric__rename_relation(from_relation, to_relation) -%}
  {% if to_relation.type == 'view' %}
    {% call statement('drop_old_view') %}
        USE [{{ to_relation.database }}];
        EXEC('DROP VIEW IF EXISTS {{ to_relation.include(database=False) }};');
    {% endcall %}
  {% endif %}
  {% call statement('rename_relation') -%}
     USE [{{ from_relation.database }}];
      EXEC sp_rename '{{ from_relation.schema }}.{{ from_relation.identifier }}', '{{ to_relation.identifier }}'
  {%- endcall %}
{% endmacro %}

It seems that this bug crept in during the "simplifications" as part of the v.1.6.1 release

prdpsvs commented 10 months ago

@itsalljustdata , I modified view materialization in 1.7.3. I am releasing this today. Could you try again after later today and see if you are still seeing this issue?

prdpsvs commented 10 months ago

Released 1.7.3, fixing this issue.