diff --git a/.changes/unreleased/Added-20240912-162707.yaml b/.changes/unreleased/Added-20240912-162707.yaml new file mode 100644 index 00000000..2acee8b3 --- /dev/null +++ b/.changes/unreleased/Added-20240912-162707.yaml @@ -0,0 +1,3 @@ +kind: Added +body: Snapshot support +time: 2024-09-12T16:27:07.67185+01:00 diff --git a/README.md b/README.md index ab5899e0..f9571cad 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ The table below shows which dbt and Firebolt features are supported by the adapt | Incremental materializations - insert_overwrite | :white_check_mark: | | Incremental materializations - delete+insert | :white_check_mark: | | Incremental materializations - merge | :x: | -| Snapshots | :x: | +| Snapshots | :white_check_mark: | | Seeds | :white_check_mark: | | Tests | :white_check_mark: | | Documentation | :white_check_mark: | diff --git a/dbt/include/firebolt/macros/materializations/snapshot_merge.sql b/dbt/include/firebolt/macros/materializations/snapshot_merge.sql new file mode 100644 index 00000000..1b98c7f5 --- /dev/null +++ b/dbt/include/firebolt/macros/materializations/snapshot_merge.sql @@ -0,0 +1,19 @@ +{% macro firebolt__snapshot_merge_sql(target, source, insert_cols) -%} + {%- set insert_cols_csv = insert_cols | join(', ') -%} + + UPDATE {{ target.render() }} AS DBT_INTERNAL_DEST + SET dbt_valid_to = DBT_INTERNAL_SOURCE.dbt_valid_to + FROM {{ source }} AS DBT_INTERNAL_SOURCE + WHERE DBT_INTERNAL_SOURCE.dbt_scd_id = DBT_INTERNAL_DEST.dbt_scd_id + AND DBT_INTERNAL_DEST.dbt_valid_to IS NULL + AND DBT_INTERNAL_SOURCE.dbt_change_type IN ('update', 'delete'); + + INSERT INTO {{ target.render() }} ({{ insert_cols_csv }}) + SELECT {{ insert_cols_csv }} + FROM {{ source }} AS DBT_INTERNAL_SOURCE + WHERE DBT_INTERNAL_SOURCE.dbt_scd_id NOT IN ( + SELECT dbt_scd_id FROM {{ target.render() }} + ) + AND DBT_INTERNAL_SOURCE.dbt_change_type = 'insert'; + +{% endmacro %} \ No newline at end of file diff --git a/dbt/include/firebolt/macros/relations/table/create.sql b/dbt/include/firebolt/macros/relations/table/create.sql index 5b5a47c8..2cd1aea4 100644 --- a/dbt/include/firebolt/macros/relations/table/create.sql +++ b/dbt/include/firebolt/macros/relations/table/create.sql @@ -24,6 +24,10 @@ ) }} {%- endif -%} + {%- if temporary -%} + {%- do adapter.drop_relation(relation) -%} + {%- endif -%} + {%- set table_type = config.get( 'table_type', default = 'dimension' diff --git a/tests/functional/adapter/test_basic.py b/tests/functional/adapter/test_basic.py index 8d4dd02c..f264ca7f 100644 --- a/tests/functional/adapter/test_basic.py +++ b/tests/functional/adapter/test_basic.py @@ -147,12 +147,10 @@ class TestGenericTestsFirebolt(BaseGenericTests): pass -@mark.skip('Not implemented for v1') class TestSnapshotCheckColsFirebolt(BaseSnapshotCheckCols): pass -@mark.skip('Not implemented for v1') class TestSnapshotTimestampFirebolt(BaseSnapshotTimestamp): pass