Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteef6fda

Browse files
authored
Merge pull request#245 from microsoft/v1.8.0
V1.8.0 release
2 parents071fb4c +da2b8a9 commiteef6fda

File tree

17 files changed

+112
-314
lines changed

17 files changed

+112
-314
lines changed

‎dbt/adapters/synapse/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version="1.8.0rc3"
1+
version="1.8.0"

‎dbt/include/synapse/macros/adapters/columns.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
path={"identifier":relation.identifier.replace("#","") ~'_tmp_tbl_hack'},
88
type='table')-%}
99

10-
{% dodrop_relation(tmp_tbl_hack) %}
10+
{% doadapter.drop_relation(tmp_tbl_hack) %}
1111
{%set sql_create %}
1212
CREATE TABLE {{ tmp_tbl_hack }}
1313
WITH(
@@ -23,7 +23,7 @@
2323
{% call statement()-%} {{ sql_create }} {%- endcall %}
2424

2525
{%set output= get_columns_in_relation(tmp_tbl_hack) %}
26-
{% dodrop_relation(tmp_tbl_hack) %}
26+
{% doadapter.drop_relation(tmp_tbl_hack) %}
2727
{{ return(output) }}
2828
{% endif %}
2929

‎dbt/include/synapse/macros/adapters/metadata.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
{%- macro synapse__get_use_database_sql(database)-%}
2+
{%- endmacro-%}
3+
4+
{%- macro default__get_use_database_sql(database)-%}
5+
{{ return('') }}
6+
{%- endmacro-%}
7+
18
{% macro synapse__list_schemas(database) %}
29
{% call statement('list_schemas', fetch_result=True, auto_begin=False)-%}
310
select nameas [schema]
@@ -8,6 +15,7 @@
815

916
{% macro synapse__list_relations_without_caching(schema_relation) %}
1017
{% call statement('list_relations_without_caching', fetch_result=True)-%}
18+
{{ get_use_database_sql(schema_relation.database) }}
1119
select
1220
table_catalogas [database],
1321
table_nameas [name],
@@ -26,6 +34,7 @@
2634

2735
{% macro synapse__get_relation_without_caching(schema_relation)-%}
2836
{% call statement('list_relations_without_caching', fetch_result=True)-%}
37+
{{ get_use_database_sql(schema_relation.database) }}
2938
select
3039
table_catalogas [database],
3140
table_nameas [name],

‎dbt/include/synapse/macros/adapters/relation.sql

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,12 @@
1-
{% macro synapse__drop_relation(relation)-%}
2-
{% call statement('drop_relation', auto_begin=False)-%}
3-
{{ synapse__drop_relation_script(relation) }}
4-
{%- endcall %}
5-
{% endmacro %}
6-
7-
{% macro synapse__drop_relation_script(relation)-%}
8-
{% if relation is not none %}
1+
{% macro synapse__get_drop_sql(relation)-%}
92
{% ifrelation.type=='view'orrelation.type=='materialized_view'-%}
103
{%set object_id_type='V' %}
114
{% elifrelation.type=='table'%}
125
{%set object_id_type='U' %}
136
{%- else-%} invalid target name
147
{% endif %}
15-
if object_id ('{{ relation }}','{{ object_id_type }}')is not null
16-
{% ifrelation.type=='view'orrelation.type=='materialized_view'-%}
17-
begin
18-
dropview {{ relation }}
19-
end
20-
{% elifrelation.type=='table' %}
21-
begin
22-
drop {{relation.type }} {{ relation }}
23-
end
24-
{% endif %}
25-
{% else %}
26-
-- no object to drop
27-
select1as nothing
28-
{% endif %}
8+
if object_id ('{{ relation }}','{{ object_id_type }}')is not null
9+
drop {{relation.type }} {{ relation }}
2910
{% endmacro %}
3011

3112
{% macro synapse__rename_relation(from_relation, to_relation)-%}

‎dbt/include/synapse/macros/adapters/replace.sql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,24 @@
2626
{{ get_create_intermediate_sql(target_relation, sql) }};
2727
{{ get_create_backup_sql(existing_relation) }};
2828
{{ get_rename_intermediate_sql(target_relation) }};
29-
{{ synapse__drop_relation(existing_relation)}}
29+
{% doadapter.drop_relation(existing_relation)%}
3030

3131
{# /* create target_relation as an intermediate relation, then swap it out with the existing one without using a backup */ #}
3232
{%- eliftarget_relation.can_be_renamed-%}
3333
{{ get_create_intermediate_sql(target_relation, sql) }};
34-
{{ synapse__drop_relation(existing_relation)}};
34+
{% doadapter.drop_relation(existing_relation)%}
3535
{{ get_rename_intermediate_sql(target_relation) }}
3636

3737
{# /* create target_relation in place by first backing up the existing relation */ #}
3838
{%- elifexisting_relation.can_be_renamed-%}
3939
{{ get_create_backup_sql(existing_relation) }};
4040
{{ get_create_sql(target_relation, sql) }};
41-
{{ synapse__drop_relation(existing_relation)}}
41+
{% doadapter.drop_relation(existing_relation)%}
4242

4343
{# /* no renaming is allowed, so just drop and create */ #}
4444
{%- else-%}
4545
{{ synapse__drop_relation(existing_relation) }};
46+
{% doadapter.drop_relation(existing_relation) %}
4647
{{ get_create_sql(target_relation, sql) }}
4748

4849
{%- endif-%}

‎dbt/include/synapse/macros/adapters/schema.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
{% macro synapse__create_schema_with_authorization(relation, schema_authorization)-%}
1111
{% call statement('create_schema')-%}
12+
1213
IF NOT EXISTS (SELECT*FROMsys.schemasWHERE name='{{ relation.schema }}')
1314
BEGIN
1415
EXEC('CREATE SCHEMA [{{ relation.schema }}] AUTHORIZATION [{{ schema_authorization }}]')
@@ -25,7 +26,7 @@
2526
identifier=row[1],
2627
type=row[3]
2728
)-%}
28-
{% do drop_relation(schema_relation) %}
29+
{% doadapter.drop_relation(schema_relation) %}
2930
{%- endfor %}
3031

3132
{% call statement('drop_schema')-%}

‎dbt/include/synapse/macros/materializations/models/materialized_view/materialized_view.sql

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
they return none
3333

3434
-- drop the temp relations if they exist already in the database
35-
{{ synapse__drop_relation(preexisting_backup_relation) }}
36-
{{ synapse__drop_relation(preexisting_intermediate_relation) }}
35+
{% doadapter.drop_relation(preexisting_backup_relation) %}
36+
{% doadapter.drop_relation(preexisting_intermediate_relation) %}
37+
3738

3839
{{ run_hooks(pre_hooks, inside_transaction=False) }}
3940

@@ -43,8 +44,9 @@
4344
{% macro materialized_view_teardown(backup_relation, intermediate_relation, post_hooks) %}
4445

4546
-- drop the temp relations if they exist to leave the database clean for the next run
46-
{{ synapse__drop_relation_script(backup_relation) }}
47-
{{ synapse__drop_relation_script(intermediate_relation) }}
47+
48+
{% doadapter.drop_relation(backup_relation) %}
49+
{% doadapter.drop_relation(intermediate_relation) %}
4850

4951
{{ run_hooks(post_hooks, inside_transaction=False) }}
5052

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,25 @@
1+
-- Need to check why model contract are not enforced.
2+
-- TODO: Is it because Synapse uses Fabric table materialization and usage of this macro build model constraints?
13
{% macro synapse__create_table_as(temporary, relation, sql)-%}
2-
{%-set index=config.get('index', default="CLUSTERED COLUMNSTORE INDEX")-%}
3-
{%-set dist=config.get('dist', default="ROUND_ROBIN")-%}
4-
{%set tmp_relation=relation.incorporate(
5-
path={"identifier":relation.identifier.replace("#","") ~'_temp_view'},
6-
type='view')-%}
7-
{%-set temp_view_sql=sql.replace("'","''")-%}
4+
{%-set index=config.get('index', default="CLUSTERED COLUMNSTORE INDEX")-%}
5+
{%-set dist=config.get('dist', default="ROUND_ROBIN")-%}
6+
{%set tmp_relation=relation.incorporate(path={"identifier":relation.identifier ~'__dbt_tmp_vw'}, type='view')-%}
7+
{%-set temp_view_sql=sql.replace("'","''")-%}
88

9-
{{ synapse__drop_relation_script(tmp_relation) }}
9+
{{ get_create_view_as_sql(tmp_relation, sql) }}
10+
{%set contract_config=config.get('contract') %}
1011

11-
{{ synapse__drop_relation_script(relation) }}
12-
13-
{{ synapse__create_view_as(tmp_relation, sql) }}
14-
15-
{%set contract_config=config.get('contract') %}
16-
17-
{% ifcontract_config.enforced %}
12+
{% ifcontract_config.enforced %}
1813

1914
{{exceptions.warn("Model contracts cannot be enforced by <adapter>!")}}
2015

2116
CREATE TABLE [{{relation.schema}}].[{{relation.identifier}}]
2217
{{ synapse__build_columns_constraints(tmp_relation) }}
2318
WITH(
24-
DISTRIBUTION= {{dist}},
25-
{{index}}
19+
DISTRIBUTION= {{dist}},
20+
{{index}}
2621
)
2722
{{ get_assert_columns_equivalent(sql) }}
28-
2923
{%set listColumns %}
3024
{% for columnin model['columns'] %}
3125
{{"["~column~"]" }}{{"," if notloop.last }}
@@ -34,11 +28,8 @@
3428

3529
INSERT INTO [{{relation.schema}}].[{{relation.identifier}}]
3630
({{listColumns}})SELECT {{listColumns}}FROM [{{tmp_relation.schema}}].[{{tmp_relation.identifier}}]
37-
3831
{%- else %}
3932
EXEC('CREATE TABLE [{{relation.database}}].[{{relation.schema}}].[{{relation.identifier}}]WITH(DISTRIBUTION = {{dist}},{{index}}) AS (SELECT * FROM [{{tmp_relation.database}}].[{{tmp_relation.schema}}].[{{tmp_relation.identifier}}]);');
4033
{% endif %}
41-
42-
{{ synapse__drop_relation_script(tmp_relation) }}
43-
34+
{% doadapter.drop_relation(tmp_relation)%}
4435
{% endmacro %}

‎dbt/include/synapse/macros/materializations/models/view/create_view_as.sql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
{% macro synapse__create_view_as(relation, sql)-%}
22

33
{%-set temp_view_sql=sql.replace("'","''")-%}
4-
54
{%set contract_config=config.get('contract') %}
65

7-
86
{% ifcontract_config.enforced %}
9-
{{exceptions.warn("Model contracts cannot be enforced by <adapter>!" }}
7+
{{exceptions.warn("Model contracts cannot be enforced by <adapter>!") }}
108
{{ get_assert_columns_equivalent(sql) }}
119
{%- endif %}
1210

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{% macro synapse__get_test_sql(main_sql, fail_calc, warn_if, error_if,limit)-%}
2+
3+
-- Create target schema in synapse db if it does not
4+
IF NOT EXISTS (SELECT*FROMsys.schemasWHERE name='{{ target.schema }}')
5+
BEGIN
6+
EXEC('CREATE SCHEMA [{{ target.schema }}]')
7+
END
8+
9+
{% ifmain_sql.strip().lower().startswith('with') %}
10+
{%set testview %}
11+
{{target.schema }}.testview_{{ range(1300,19000) | random }}
12+
{% endset %}
13+
14+
{%set sql=main_sql.replace("'","''")%}
15+
EXEC('create view {{testview}} as {{ sql }};')
16+
select
17+
{{"top (" ~limit ~')' iflimit!= none }}
18+
{{ fail_calc }}as failures,
19+
case when {{ fail_calc }} {{ warn_if }}
20+
then'true' else'false' endas should_warn,
21+
case when {{ fail_calc }} {{ error_if }}
22+
then'true' else'false' endas should_error
23+
from (
24+
select*from {{testview}}
25+
) dbt_internal_test;
26+
27+
EXEC('drop view {{testview}};')
28+
29+
{% else-%}
30+
select
31+
{{"top (" ~limit ~')' iflimit!= none }}
32+
{{ fail_calc }}as failures,
33+
case when {{ fail_calc }} {{ warn_if }}
34+
then'true' else'false' endas should_warn,
35+
case when {{ fail_calc }} {{ error_if }}
36+
then'true' else'false' endas should_error
37+
from (
38+
{{ main_sql }}
39+
) dbt_internal_test
40+
{%- endif-%}
41+
{%- endmacro %}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp