-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
234 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version = "1.7.2" | ||
version = "1.7.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 9 additions & 3 deletions
12
dbt/include/fabric/macros/materializations/models/table/columns_spec_ddl.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
{% macro fabric__table_columns_and_constraints(relation) %} | ||
{% macro fabric__build_columns_constraints(relation) %} | ||
{# loop through user_provided_columns to create DDL with data types and constraints #} | ||
{%- set raw_column_constraints = adapter.render_raw_columns_constraints(raw_columns=model['columns']) -%} | ||
{%- set raw_model_constraints = adapter.render_raw_model_constraints(raw_constraints=model['constraints']) -%} | ||
( | ||
{% for c in raw_column_constraints -%} | ||
{{ c }}{{ "," if not loop.last }} | ||
{% endfor %} | ||
) | ||
{% endmacro %} | ||
|
||
{% macro fabric__build_model_constraints(relation) %} | ||
{# loop through user_provided_columns to create DDL with data types and constraints #} | ||
{%- set raw_model_constraints = adapter.render_raw_model_constraints(raw_constraints=model['constraints']) -%} | ||
{% for c in raw_model_constraints -%} | ||
{% set alter_table_script %} | ||
alter table {{ relation.include(database=False) }} {{c}}; | ||
{%endset%} | ||
EXEC('{{alter_table_script}};') | ||
{% call statement('alter_table_add_constraint') -%} | ||
{{alter_table_script}} | ||
{%- endcall %} | ||
{% endfor -%} | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
dbt/include/fabric/macros/materializations/models/table/table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{% materialization table, adapter='fabric' %} | ||
|
||
-- Create target relation | ||
{%- set target_relation = this.incorporate(type='table') %} | ||
-- grab current tables grants config for comparision later on | ||
{% set grant_config = config.get('grants') %} | ||
{%- set backup_relation = make_backup_relation(target_relation, 'table') -%} | ||
-- drop the temp relations if they exist already in the database | ||
{{ drop_relation_if_exists(backup_relation) }} | ||
-- Rename target relation as backup relation | ||
{%- set relation = fabric__get_relation_without_caching(target_relation) %} | ||
{% if relation|length > 0 %} | ||
{{ adapter.rename_relation(target_relation, backup_relation) }} | ||
{% endif %} | ||
|
||
{{ run_hooks(pre_hooks, inside_transaction=False) }} | ||
-- `BEGIN` happens here: | ||
{{ run_hooks(pre_hooks, inside_transaction=True) }} | ||
|
||
-- build model | ||
{% call statement('main') -%} | ||
{{ get_create_table_as_sql(False, target_relation, sql) }} | ||
{%- endcall %} | ||
|
||
-- cleanup | ||
{{ run_hooks(post_hooks, inside_transaction=True) }} | ||
{% do apply_grants(target_relation, grant_config, should_revoke=should_revoke) %} | ||
{% do persist_docs(target_relation, model) %} | ||
-- `COMMIT` happens here | ||
{{ adapter.commit() }} | ||
|
||
-- finally, drop the foreign key references if exists | ||
{{ drop_fk_indexes_on_table(backup_relation) }} | ||
-- drop existing/backup relation after the commit | ||
{{ drop_relation_if_exists(backup_relation) }} | ||
-- Add constraints including FK relation. | ||
{{ fabric__build_model_constraints(target_relation) }} | ||
{{ run_hooks(post_hooks, inside_transaction=False) }} | ||
{{ return({'relations': [target_relation]}) }} | ||
|
||
{% endmaterialization %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
dbt/include/fabric/macros/materializations/models/view/view.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{% materialization view, adapter='fabric' -%} | ||
|
||
{%- set existing_relation = load_cached_relation(this) -%} | ||
{%- set target_relation = this.incorporate(type='view') -%} | ||
|
||
-- make back up relation | ||
{%- set backup_relation_type = 'view' if existing_relation is none else existing_relation.type -%} | ||
{%- set backup_relation = make_backup_relation(target_relation, backup_relation_type) -%} | ||
|
||
{% set grant_config = config.get('grants') %} | ||
{{ run_hooks(pre_hooks, inside_transaction=False) }} | ||
|
||
-- drop target relation if exists already in the database | ||
{{ drop_relation_if_exists(backup_relation) }} | ||
|
||
{%- set relation = fabric__get_relation_without_caching(target_relation) %} | ||
{% if relation|length > 0 %} | ||
{{ adapter.rename_relation(target_relation, backup_relation) }} | ||
{% endif %} | ||
|
||
-- `BEGIN` happens here: | ||
{{ run_hooks(pre_hooks, inside_transaction=True) }} | ||
|
||
-- build model | ||
{% call statement('main') -%} | ||
{{ get_create_view_as_sql(target_relation, sql) }} | ||
{%- endcall %} | ||
|
||
{% set should_revoke = should_revoke(existing_relation, full_refresh_mode=True) %} | ||
{% do apply_grants(target_relation, grant_config, should_revoke=should_revoke) %} | ||
|
||
{% do persist_docs(target_relation, model) %} | ||
{{ run_hooks(post_hooks, inside_transaction=True) }} | ||
{{ adapter.commit() }} | ||
{{ drop_relation_if_exists(backup_relation) }} | ||
{{ run_hooks(post_hooks, inside_transaction=False) }} | ||
|
||
{{ return({'relations': [target_relation]}) }} | ||
|
||
{%- endmaterialization -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
pytest==7.4.3 | ||
pytest==7.4.4 | ||
twine==4.0.2 | ||
wheel==0.42 | ||
pre-commit==3.5.0 | ||
pre-commit==3.6.0 | ||
pytest-dotenv==0.5.2 | ||
dbt-tests-adapter~=1.7.3 | ||
dbt-tests-adapter~=1.7.4 | ||
flaky==3.7.0 | ||
pytest-xdist==3.5.0 | ||
-e . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters