Skip to content

Commit d4f99e7

Browse files
authored
Merge pull request #192 from microsoft/v1.8.7
Addressing issues 189, 188, 181, 179, #197
2 parents 4ed06da + faa2cb0 commit d4f99e7

File tree

18 files changed

+289
-234
lines changed

18 files changed

+289
-234
lines changed

.github/workflows/publish-docker.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
uses: actions/checkout@v4
2525

2626
- name: Log in to the Container registry
27-
uses: docker/login-action@v3.0.0
27+
uses: docker/login-action@v3.3.0
2828
with:
2929
registry: ghcr.io
3030
username: ${{ github.actor }}

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
### V1.8.7
4+
* Improving table materialization to minimize downtime #189
5+
* Handling temp tables in incremental models #188
6+
* Add label support to filter queries #181
7+
* Addressed bug - incremental models cannot full refresh #179
8+
* Addressed bug - #197, dbt test incorrect syntax with macro helpers.sql
9+
310
### v1.8.0rc2
411

512
## Bug Fixes

dbt/adapters/fabric/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = "1.8.6"
1+
version = "1.8.7"

dbt/include/fabric/macros/adapters/catalog.sql

+122-121
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,132 @@
11
{% macro fabric__get_catalog(information_schemas, schemas) -%}
2+
{% set query_label = apply_label() %}
3+
{%- call statement('catalog', fetch_result=True) -%}
24

3-
{%- call statement('catalog', fetch_result=True) -%}
4-
5-
with
6-
principals as (
7-
select
8-
name as principal_name,
9-
principal_id as principal_id
10-
from
11-
sys.database_principals {{ information_schema_hints() }}
12-
),
13-
14-
schemas as (
15-
select
16-
name as schema_name,
17-
schema_id as schema_id,
18-
principal_id as principal_id
19-
from
20-
sys.schemas {{ information_schema_hints() }}
21-
),
22-
23-
tables as (
24-
select
25-
object_id,
26-
name as table_name,
27-
schema_id as schema_id,
28-
principal_id as principal_id,
29-
'BASE TABLE' as table_type
30-
from
31-
sys.tables {{ information_schema_hints() }}
32-
),
33-
34-
tables_with_metadata as (
35-
select
36-
object_id,
37-
table_name,
38-
schema_name,
39-
coalesce(tables.principal_id, schemas.principal_id) as owner_principal_id,
40-
table_type
41-
from
42-
tables
43-
join schemas on tables.schema_id = schemas.schema_id
44-
),
45-
46-
views as (
47-
select
48-
object_id,
49-
name as table_name,
50-
schema_id as schema_id,
51-
principal_id as principal_id,
52-
'VIEW' as table_type
53-
from
54-
sys.views {{ information_schema_hints() }}
55-
),
56-
57-
views_with_metadata as (
58-
select
59-
object_id,
60-
table_name,
61-
schema_name,
62-
coalesce(views.principal_id, schemas.principal_id) as owner_principal_id,
63-
table_type
64-
from
65-
views
66-
join schemas on views.schema_id = schemas.schema_id
67-
),
68-
69-
tables_and_views as (
70-
select
71-
object_id,
72-
table_name,
73-
schema_name,
74-
principal_name,
75-
table_type
76-
from
77-
tables_with_metadata
78-
join principals on tables_with_metadata.owner_principal_id = principals.principal_id
79-
union all
80-
select
81-
object_id,
82-
table_name,
83-
schema_name,
84-
principal_name,
85-
table_type
86-
from
87-
views_with_metadata
88-
join principals on views_with_metadata.owner_principal_id = principals.principal_id
89-
),
90-
91-
cols as (
5+
with
6+
principals as (
7+
select
8+
name as principal_name,
9+
principal_id as principal_id
10+
from
11+
sys.database_principals {{ information_schema_hints() }}
12+
),
13+
14+
schemas as (
15+
select
16+
name as schema_name,
17+
schema_id as schema_id,
18+
principal_id as principal_id
19+
from
20+
sys.schemas {{ information_schema_hints() }}
21+
),
22+
23+
tables as (
24+
select
25+
object_id,
26+
name as table_name,
27+
schema_id as schema_id,
28+
principal_id as principal_id,
29+
'BASE TABLE' as table_type
30+
from
31+
sys.tables {{ information_schema_hints() }}
32+
),
33+
34+
tables_with_metadata as (
35+
select
36+
object_id,
37+
table_name,
38+
schema_name,
39+
coalesce(tables.principal_id, schemas.principal_id) as owner_principal_id,
40+
table_type
41+
from
42+
tables
43+
join schemas on tables.schema_id = schemas.schema_id
44+
),
45+
46+
views as (
47+
select
48+
object_id,
49+
name as table_name,
50+
schema_id as schema_id,
51+
principal_id as principal_id,
52+
'VIEW' as table_type
53+
from
54+
sys.views {{ information_schema_hints() }}
55+
),
56+
57+
views_with_metadata as (
58+
select
59+
object_id,
60+
table_name,
61+
schema_name,
62+
coalesce(views.principal_id, schemas.principal_id) as owner_principal_id,
63+
table_type
64+
from
65+
views
66+
join schemas on views.schema_id = schemas.schema_id
67+
),
68+
69+
tables_and_views as (
70+
select
71+
object_id,
72+
table_name,
73+
schema_name,
74+
principal_name,
75+
table_type
76+
from
77+
tables_with_metadata
78+
join principals on tables_with_metadata.owner_principal_id = principals.principal_id
79+
union all
80+
select
81+
object_id,
82+
table_name,
83+
schema_name,
84+
principal_name,
85+
table_type
86+
from
87+
views_with_metadata
88+
join principals on views_with_metadata.owner_principal_id = principals.principal_id
89+
),
90+
91+
cols as (
92+
93+
select
94+
c.object_id,
95+
c.name as column_name,
96+
c.column_id as column_index,
97+
t.name as column_type
98+
from sys.columns as c {{ information_schema_hints() }}
99+
left join sys.types as t on c.system_type_id = t.system_type_id {{ information_schema_hints() }}
100+
)
92101

93102
select
94-
c.object_id,
95-
c.name as column_name,
96-
c.column_id as column_index,
97-
t.name as column_type
98-
from sys.columns as c {{ information_schema_hints() }}
99-
left join sys.types as t on c.system_type_id = t.system_type_id {{ information_schema_hints() }}
100-
)
101-
102-
select
103-
DB_NAME() as table_database,
104-
tv.schema_name as table_schema,
105-
tv.table_name,
106-
tv.table_type,
107-
null as table_comment,
108-
tv.principal_name as table_owner,
109-
cols.column_name,
110-
cols.column_index,
111-
cols.column_type,
112-
null as column_comment
113-
from tables_and_views tv
114-
join cols on tv.object_id = cols.object_id
115-
where ({%- for schema in schemas -%}
116-
upper(tv.schema_name) = upper('{{ schema }}'){%- if not loop.last %} or {% endif -%}
117-
{%- endfor -%})
118-
119-
order by column_index
120-
121-
{%- endcall -%}
122-
123-
{{ return(load_result('catalog').table) }}
103+
DB_NAME() as table_database,
104+
tv.schema_name as table_schema,
105+
tv.table_name,
106+
tv.table_type,
107+
null as table_comment,
108+
tv.principal_name as table_owner,
109+
cols.column_name,
110+
cols.column_index,
111+
cols.column_type,
112+
null as column_comment
113+
from tables_and_views tv
114+
join cols on tv.object_id = cols.object_id
115+
where ({%- for schema in schemas -%}
116+
upper(tv.schema_name) = upper('{{ schema }}'){%- if not loop.last %} or {% endif -%}
117+
{%- endfor -%})
118+
119+
order by column_index
120+
{{ query_label }}
121+
122+
{%- endcall -%}
123+
124+
{{ return(load_result('catalog').table) }}
124125

125126
{%- endmacro %}
126127

127128
{% macro fabric__get_catalog_relations(information_schema, relations) -%}
128-
129+
{% set query_label = apply_label() %}
129130
{%- call statement('catalog', fetch_result=True) -%}
130131

131132
with
@@ -260,7 +261,7 @@
260261
)
261262

262263
order by column_index
263-
264+
{{ query_label }}
264265
{%- endcall -%}
265266

266267
{{ return(load_result('catalog').table) }}

dbt/include/fabric/macros/adapters/columns.sql

+32-27
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,46 @@
1111
{% endmacro %}
1212

1313
{% macro fabric__get_columns_in_relation(relation) -%}
14-
{% call statement('get_columns_in_relation', fetch_result=True) %}
14+
{% set query_label = apply_label() %}
15+
{% call statement('get_columns_in_relation', fetch_result=True) %}
16+
17+
with mapping as (
18+
select
19+
row_number() over (partition by object_name(c.object_id) order by c.column_id) as ordinal_position,
20+
c.name collate database_default as column_name,
21+
t.name as data_type,
22+
c.max_length as character_maximum_length,
23+
c.precision as numeric_precision,
24+
c.scale as numeric_scale
25+
from [{{ 'tempdb' if '#' in relation.identifier else relation.database }}].sys.columns c {{ information_schema_hints() }}
26+
inner join sys.types t {{ information_schema_hints() }}
27+
on c.user_type_id = t.user_type_id
28+
where c.object_id = object_id('{{ 'tempdb..' ~ relation.include(database=false, schema=false) if '#' in relation.identifier else relation }}')
29+
)
1530

16-
with mapping as (
1731
select
18-
row_number() over (partition by object_name(c.object_id) order by c.column_id) as ordinal_position,
19-
c.name collate database_default as column_name,
20-
t.name as data_type,
21-
c.max_length as character_maximum_length,
22-
c.precision as numeric_precision,
23-
c.scale as numeric_scale
24-
from [{{ 'tempdb' if '#' in relation.identifier else relation.database }}].sys.columns c {{ information_schema_hints() }}
25-
inner join sys.types t {{ information_schema_hints() }}
26-
on c.user_type_id = t.user_type_id
27-
where c.object_id = object_id('{{ 'tempdb..' ~ relation.include(database=false, schema=false) if '#' in relation.identifier else relation }}')
28-
)
29-
30-
select
31-
column_name,
32-
data_type,
33-
character_maximum_length,
34-
numeric_precision,
35-
numeric_scale
36-
from mapping
37-
order by ordinal_position
38-
39-
{% endcall %}
40-
{% set table = load_result('get_columns_in_relation').table %}
41-
{{ return(sql_convert_columns_in_relation(table)) }}
32+
column_name,
33+
data_type,
34+
character_maximum_length,
35+
numeric_precision,
36+
numeric_scale
37+
from mapping
38+
order by ordinal_position
39+
{{ query_label }}
40+
41+
{% endcall %}
42+
{% set table = load_result('get_columns_in_relation').table %}
43+
{{ return(sql_convert_columns_in_relation(table)) }}
4244
{% endmacro %}
4345

4446
{% macro fabric__get_columns_in_query(select_sql) %}
47+
{% set query_label = apply_label() %}
4548
{% call statement('get_columns_in_query', fetch_result=True, auto_begin=False) -%}
4649
select TOP 0 * from (
4750
{{ select_sql }}
4851
) as __dbt_sbq
4952
where 0 = 1
53+
{{ query_label }}
5054
{% endcall %}
5155

5256
{{ return(load_result('get_columns_in_query').table.columns | map(attribute='name') | list) }}
@@ -84,6 +88,7 @@
8488
{% set tempTable %}
8589
CREATE TABLE {{tempTableName}}
8690
AS SELECT {{query_result_text}}, CAST({{ column_name }} AS {{new_column_type}}) AS {{column_name}} FROM {{ relation.schema }}.{{ relation.identifier }}
91+
{{ apply_label() }}
8792
{% endset %}
8893

8994
{% call statement('create_temp_table') -%}
@@ -100,7 +105,7 @@
100105

101106
{% set createTable %}
102107
CREATE TABLE {{ relation.schema }}.{{ relation.identifier }}
103-
AS SELECT * FROM {{tempTableName}}
108+
AS SELECT * FROM {{tempTableName}} {{ apply_label() }}
104109
{% endset %}
105110

106111
{% call statement('create_Table') -%}

0 commit comments

Comments
 (0)