-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dbtsynapse1.6_dataroots' of github.com:microsoft/dbt-sy…
…napse into dbtsynapse1.7_dataroots
- Loading branch information
Showing
33 changed files
with
2,432 additions
and
27 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from dbt.adapters.fabric import FabricColumn | ||
|
||
|
||
class SynapseColumn(FabricColumn): | ||
# extending list of integer types for synapse | ||
def is_integer(self) -> bool: | ||
return self.dtype.lower() in [ | ||
# real types | ||
"smallint", | ||
"bigint", | ||
"tinyint", | ||
"serial", | ||
"bigserial", | ||
"int", | ||
"bit", | ||
] |
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,4 @@ | ||
{# Unfortunately adding docs via extended properties is not supported in Synapse only in SQLServer | ||
https://github.com/dbt-msft/dbt-sqlserver/issues/134 | ||
https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-addextendedproperty-transact-sql?view=sql-server-ver16 | ||
#} |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{% macro get_show_sql(compiled_code, sql_header, limit) -%} | ||
{%- if sql_header -%} | ||
{{ sql_header }} | ||
{%- endif -%} | ||
{%- if limit is not none -%} | ||
{{ get_limit_subquery_sql(compiled_code, limit) }} | ||
{%- else -%} | ||
{{ compiled_code }} | ||
{%- endif -%} | ||
{% endmacro %} | ||
|
||
{% macro get_limit_subquery_sql(sql, limit) %} | ||
{{ adapter.dispatch('get_limit_subquery_sql', 'dbt')(sql, limit) }} | ||
{% endmacro %} | ||
|
||
{# Synapse doesnt support ANSI LIMIT clause #} | ||
{% macro synapse__get_limit_subquery_sql(sql, limit) %} | ||
select top {{ limit }} * | ||
from ( | ||
{{ sql }} | ||
) as model_limit_subq | ||
{% endmacro %} |
29 changes: 29 additions & 0 deletions
29
dbt/include/synapse/macros/materializations/models/materialized_view/materialized_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,29 @@ | ||
{% macro ref(model_name) %} | ||
|
||
{% do return(builtins.ref(model_name).include(database=false)) %} | ||
|
||
{% endmacro %} | ||
|
||
{% macro synapse__get_replace_materialized_view_as_sql(relation, sql, existing_relation, backup_relation, intermediate_relation) %} | ||
{# Synapse does not have ALTER...RENAME function, so use synapse__rename_relation_script #} | ||
|
||
{%- set dist = config.get('dist', default="ROUND_ROBIN") -%} | ||
EXEC(' | ||
CREATE materialized view {{ intermediate_relation.include(database=False) }} | ||
WITH ( DISTRIBUTION = {{dist}} ) | ||
AS {{ sql }} | ||
'); | ||
|
||
{{ synapse__rename_relation_script(existing_relation, backup_relation) }} | ||
{{ synapse__rename_relation_script(intermediate_relation, relation) }} | ||
|
||
{% endmacro %} | ||
|
||
{% macro synapse__get_create_materialized_view_as_sql(relation, sql) %} | ||
{%- set dist = config.get('dist', default="ROUND_ROBIN") -%} | ||
|
||
CREATE materialized view {{ relation.include(database=False) }} | ||
WITH ( DISTRIBUTION = {{dist}} ) | ||
AS {{ sql }} | ||
|
||
{% 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
17 changes: 17 additions & 0 deletions
17
dbt/include/synapse/macros/materializations/models/table/create_table_constraints.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,17 @@ | ||
{% macro synapse__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']) -%} | ||
( | ||
{% for c in raw_column_constraints -%} | ||
{{ c }}{{ "," if not loop.last }} | ||
{% endfor %} | ||
) | ||
{% endmacro %} | ||
|
||
{% macro synapse__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 -%} | ||
alter table {{ relation.include(database=False) }} {{c}}; | ||
{% endfor -%} | ||
{% endmacro %} |
15 changes: 13 additions & 2 deletions
15
dbt/include/synapse/macros/materializations/models/view/create_view_as.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,4 +1,15 @@ | ||
{% macro synapse__create_view_as(relation, sql) -%} | ||
create view {{ relation.include(database=False) }} as | ||
{{ sql }} | ||
|
||
{%- set temp_view_sql = sql.replace("'", "''") -%} | ||
|
||
{% set contract_config = config.get('contract') %} | ||
|
||
{{exceptions.warn("Model contracts cannot be enforced by <adapter>!")}} | ||
|
||
{% if contract_config.enforced %} | ||
{{ get_assert_columns_equivalent(sql) }} | ||
{%- endif %} | ||
|
||
EXEC('create view {{ relation.include(database=False) }} as {{ temp_view_sql }};'); | ||
|
||
{% 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
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
Oops, something went wrong.