Skip to content

Commit

Permalink
Merge pull request #12 from firebolt-db/run_twice_workaround
Browse files Browse the repository at this point in the history
temp workaround for false approximate match
  • Loading branch information
dataders authored Nov 17, 2021
2 parents 9ae398e + 129f80f commit 47dfc52
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog


## v.0.21.3

## Changes

- temporary workaround for #11 where running models twice fails [#12](https://github.com/firebolt-db/dbt-firebolt/pull/12)

## v.0.21.2

### Readme
Expand Down
2 changes: 1 addition & 1 deletion dbt/adapters/firebolt/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "0.21.2"
version = "0.21.3"
22 changes: 14 additions & 8 deletions dbt/include/firebolt/macros/materializations/table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@
{# Note that a nearly identical materialization appears
in table.sql #}
{%- set identifier = model['alias'] -%} {# alias comes from where? #}
{%- set old_relation = adapter.get_relation(database=database,
schema=schema,
identifier=identifier) -%}

{# Temporary workaround to issue with adapter.get_relation() until
the following are resolved:
https://github.com/firebolt-db/dbt-firebolt/issues/11
https://github.com/dbt-labs/dbt-core/issues/4187
the hack is to always drop the view/table if it already exists rather than
checking the db first to see if it exists.
#}
{%- set target_relation = api.Relation.create(database=database,
schema=schema,
identifier=identifier,
type='table') -%}
{%- set exists_as_table = (old_relation is not none and old_relation.is_table) -%}
{%- set exists_as_view = (old_relation is not none and old_relation.is_view) -%}
{%- set target_relation_view = api.Relation.create(database=database,
schema=schema,
identifier=identifier,
type='view') -%}

{{ run_hooks(pre_hooks) }}

{% if old_relation is not none %}
{% do adapter.drop_relation(old_relation) %}
{% endif %}
{% do adapter.drop_relation(target_relation) %}
{% do adapter.drop_relation(target_relation_view) %}

-- build model
{% call statement('main') -%}
Expand Down

0 comments on commit 47dfc52

Please sign in to comment.