Skip to content

Commit 4bd7ea9

Browse files
authored
V1.8.8 draft (#251)
* configuring local tests to run on user credentials. Dropping a relation correctly based on its type * Addressing #243, #221, #228, #229, #232, #235 issues * Updated test helper with ephemeral * Updated unit tests * Updated get_pyodbc_attrs_before_credentials method * include only lines that start with order by * Addressed issue #249,#240,#238,#233,#180,#168,#186,#52 * Ensure Testview Name Uniqueness with MD5 of Model Name and Invocation * Updating integration tests
1 parent 525fe95 commit 4bd7ea9

18 files changed

+744
-969
lines changed

.github/workflows/integration-tests-azure.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
name: Integration tests on Fabric DW
23
on: # yamllint disable-line rule:truthy
34
workflow_dispatch:

dbt/adapters/fabric/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = "1.8.8"
1+
version = "1.8.9"

dbt/adapters/fabric/fabric_adapter.py

+3
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ def get_rows_different_sql(
150150
names = sorted((self.quote(n) for n in column_names))
151151
columns_csv = ", ".join(names)
152152

153+
if columns_csv == "":
154+
columns_csv = "*"
155+
153156
sql = COLUMNS_EQUAL_SQL.format(
154157
columns=columns_csv,
155158
relation_a=str(relation_a),

dbt/adapters/fabric/fabric_connection_manager.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ def open(cls, connection: Connection) -> Connection:
352352
con_str.append(f"SERVER={credentials.host}")
353353

354354
con_str.append(f"Database={credentials.database}")
355+
con_str.append("Pooling=true")
355356

356357
# Enabling trace flag
357358
if credentials.trace_flag:
@@ -395,8 +396,8 @@ def open(cls, connection: Connection) -> Connection:
395396
con_str.append(f"APP={application_name}")
396397

397398
try:
398-
if int(credentials.retries) > 0:
399-
con_str.append(f"ConnectRetryCount={credentials.retries}")
399+
con_str.append("ConnectRetryCount=3")
400+
con_str.append("ConnectRetryInterval=10")
400401

401402
except Exception as e:
402403
logger.debug(
@@ -427,7 +428,7 @@ def open(cls, connection: Connection) -> Connection:
427428

428429
def connect():
429430
logger.debug(f"Using connection string: {con_str_display}")
430-
431+
pyodbc.pooling = True
431432
if credentials.authentication == "ActiveDirectoryAccessToken":
432433
attrs_before = get_pyodbc_attrs_before_accesstoken(credentials.access_token)
433434
else:
@@ -567,3 +568,4 @@ def execute(
567568
while cursor.nextset():
568569
pass
569570
return response, table
571+

dbt/adapters/fabric/fabric_credentials.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class FabricCredentials(Credentials):
2121
authentication: Optional[str] = "ActiveDirectoryServicePrincipal"
2222
encrypt: Optional[bool] = True # default value in MS ODBC Driver 18 as well
2323
trust_cert: Optional[bool] = False # default value in MS ODBC Driver 18 as well
24-
retries: int = 1
24+
retries: int = 3
2525
schema_authorization: Optional[str] = None
2626
login_timeout: Optional[int] = 0
2727
query_timeout: Optional[int] = 0
+135-125
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% macro fabric__get_catalog(information_schemas, schemas) -%}
2+
23
{% set query_label = apply_label() %}
34
{%- call statement('catalog', fetch_result=True) -%}
45

@@ -126,144 +127,153 @@
126127
{%- endmacro %}
127128

128129
{% macro fabric__get_catalog_relations(information_schema, relations) -%}
130+
129131
{% set query_label = apply_label() %}
130-
{%- call statement('catalog', fetch_result=True) -%}
132+
{%- set distinct_databases = relations | map(attribute='database') | unique | list -%}
131133

132-
with
133-
principals as (
134-
select
135-
name as principal_name,
136-
principal_id as principal_id
137-
from
138-
sys.database_principals {{ information_schema_hints() }}
139-
),
134+
{%- if distinct_databases | length == 1 -%}
135+
{%- call statement('catalog', fetch_result=True) -%}
136+
{{ get_use_database_sql(distinct_databases[0]) }}
137+
with
138+
principals as (
139+
select
140+
name as principal_name,
141+
principal_id as principal_id
142+
from
143+
sys.database_principals {{ information_schema_hints() }}
144+
),
140145

141-
schemas as (
142-
select
143-
name as schema_name,
144-
schema_id as schema_id,
145-
principal_id as principal_id
146-
from
147-
sys.schemas {{ information_schema_hints() }}
148-
),
146+
schemas as (
147+
select
148+
name as schema_name,
149+
schema_id as schema_id,
150+
principal_id as principal_id
151+
from
152+
sys.schemas {{ information_schema_hints() }}
153+
),
149154

150-
tables as (
151-
select
152-
object_id,
153-
name as table_name,
154-
schema_id as schema_id,
155-
principal_id as principal_id,
156-
'BASE TABLE' as table_type
157-
from
158-
sys.tables {{ information_schema_hints() }}
159-
),
155+
tables as (
156+
select
157+
object_id,
158+
name as table_name,
159+
schema_id as schema_id,
160+
principal_id as principal_id,
161+
'BASE TABLE' as table_type
162+
from
163+
sys.tables {{ information_schema_hints() }}
164+
),
160165

161-
tables_with_metadata as (
162-
select
163-
object_id,
164-
table_name,
165-
schema_name,
166-
coalesce(tables.principal_id, schemas.principal_id) as owner_principal_id,
167-
table_type
168-
from
169-
tables
170-
join schemas on tables.schema_id = schemas.schema_id
171-
),
166+
tables_with_metadata as (
167+
select
168+
object_id,
169+
table_name,
170+
schema_name,
171+
coalesce(tables.principal_id, schemas.principal_id) as owner_principal_id,
172+
table_type
173+
from
174+
tables
175+
join schemas on tables.schema_id = schemas.schema_id
176+
),
172177

173-
views as (
174-
select
175-
object_id,
176-
name as table_name,
177-
schema_id as schema_id,
178-
principal_id as principal_id,
179-
'VIEW' as table_type
180-
from
181-
sys.views {{ information_schema_hints() }}
182-
),
178+
views as (
179+
select
180+
object_id,
181+
name as table_name,
182+
schema_id as schema_id,
183+
principal_id as principal_id,
184+
'VIEW' as table_type
185+
from
186+
sys.views {{ information_schema_hints() }}
187+
),
183188

184-
views_with_metadata as (
185-
select
186-
object_id,
187-
table_name,
188-
schema_name,
189-
coalesce(views.principal_id, schemas.principal_id) as owner_principal_id,
190-
table_type
191-
from
192-
views
193-
join schemas on views.schema_id = schemas.schema_id
194-
),
189+
views_with_metadata as (
190+
select
191+
object_id,
192+
table_name,
193+
schema_name,
194+
coalesce(views.principal_id, schemas.principal_id) as owner_principal_id,
195+
table_type
196+
from
197+
views
198+
join schemas on views.schema_id = schemas.schema_id
199+
),
195200

196-
tables_and_views as (
197-
select
198-
object_id,
199-
table_name,
200-
schema_name,
201-
principal_name,
202-
table_type
203-
from
204-
tables_with_metadata
205-
join principals on tables_with_metadata.owner_principal_id = principals.principal_id
206-
union all
207-
select
208-
object_id,
209-
table_name,
210-
schema_name,
211-
principal_name,
212-
table_type
213-
from
214-
views_with_metadata
215-
join principals on views_with_metadata.owner_principal_id = principals.principal_id
216-
),
201+
tables_and_views as (
202+
select
203+
object_id,
204+
table_name,
205+
schema_name,
206+
principal_name,
207+
table_type
208+
from
209+
tables_with_metadata
210+
join principals on tables_with_metadata.owner_principal_id = principals.principal_id
211+
union all
212+
select
213+
object_id,
214+
table_name,
215+
schema_name,
216+
principal_name,
217+
table_type
218+
from
219+
views_with_metadata
220+
join principals on views_with_metadata.owner_principal_id = principals.principal_id
221+
),
217222

218-
cols as (
223+
cols as (
219224

220-
select
221-
c.object_id,
222-
c.name as column_name,
223-
c.column_id as column_index,
224-
t.name as column_type
225-
from sys.columns as c {{ information_schema_hints() }}
226-
left join sys.types as t on c.system_type_id = t.system_type_id
227-
)
225+
select
226+
c.object_id,
227+
c.name as column_name,
228+
c.column_id as column_index,
229+
t.name as column_type
230+
from sys.columns as c {{ information_schema_hints() }}
231+
left join sys.types as t on c.system_type_id = t.system_type_id
232+
)
228233

229-
select
230-
DB_NAME() as table_database,
231-
tv.schema_name as table_schema,
232-
tv.table_name,
233-
tv.table_type,
234-
null as table_comment,
235-
tv.principal_name as table_owner,
236-
cols.column_name,
237-
cols.column_index,
238-
cols.column_type,
239-
null as column_comment
240-
from tables_and_views tv
241-
join cols on tv.object_id = cols.object_id
242-
where (
243-
{%- for relation in relations -%}
244-
{% if relation.schema and relation.identifier %}
245-
(
246-
upper(tv.schema_name) = upper('{{ relation.schema }}')
247-
and upper(tv.table_name) = upper('{{ relation.identifier }}')
248-
)
249-
{% elif relation.schema %}
250-
(
251-
upper(tv.schema_name) = upper('{{ relation.schema }}')
252-
)
253-
{% else %}
254-
{% do exceptions.raise_compiler_error(
255-
'`get_catalog_relations` requires a list of relations, each with a schema'
256-
) %}
257-
{% endif %}
234+
select
235+
DB_NAME() as table_database,
236+
tv.schema_name as table_schema,
237+
tv.table_name,
238+
tv.table_type,
239+
null as table_comment,
240+
tv.principal_name as table_owner,
241+
cols.column_name,
242+
cols.column_index,
243+
cols.column_type,
244+
null as column_comment
245+
from tables_and_views tv
246+
join cols on tv.object_id = cols.object_id
247+
where (
248+
{%- for relation in relations -%}
249+
{% if relation.schema and relation.identifier %}
250+
(
251+
upper(tv.schema_name) = upper('{{ relation.schema }}')
252+
and upper(tv.table_name) = upper('{{ relation.identifier }}')
253+
)
254+
{% elif relation.schema %}
255+
(
256+
upper(tv.schema_name) = upper('{{ relation.schema }}')
257+
)
258+
{% else %}
259+
{% do exceptions.raise_compiler_error(
260+
'`get_catalog_relations` requires a list of relations, each with a schema'
261+
) %}
262+
{% endif %}
258263

259-
{%- if not loop.last %} or {% endif -%}
260-
{%- endfor -%}
261-
)
264+
{%- if not loop.last %} or {% endif -%}
265+
{%- endfor -%}
266+
)
262267

263-
order by column_index
264-
{{ query_label }}
265-
{%- endcall -%}
268+
order by column_index
269+
{{ query_label }}
266270

267-
{{ return(load_result('catalog').table) }}
271+
{%- endcall -%}
272+
{{ return(load_result('catalog').table) }}
273+
{% else %}
274+
{% do exceptions.raise_compiler_error(
275+
'`get_catalog_relations` can catalog one database at a time'
276+
) %}
277+
{% endif %}
268278

269279
{%- endmacro %}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
{% endmacro %}
2222

2323
{%- macro fabric__get_use_database_sql(database) -%}
24-
USE [{{database}}];
24+
USE [{{database | replace('"', '')}}];
2525
{%- endmacro -%}
2626

2727
{% macro fabric__list_schemas(database) %}
2828
{% call statement('list_schemas', fetch_result=True, auto_begin=False) -%}
29+
{{ get_use_database_sql(database) }}
2930
select name as [schema]
3031
from sys.schemas {{ information_schema_hints() }} {{ apply_label() }}
3132
{% endcall %}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
{%- endfor %}
3232

3333
{% call statement('drop_schema') -%}
34-
EXEC('DROP SCHEMA IF EXISTS {{ relation.schema }}')
34+
{{ get_use_database_sql(relation.database) }}
35+
EXEC('DROP SCHEMA IF EXISTS {{ relation.schema }}')
3536
{% endcall %}
3637
{% endmacro %}

0 commit comments

Comments
 (0)