Skip to content

Commit fefdc8c

Browse files
authored
Merge pull request #264 from microsoft/v1.9.2
V1.9.2
2 parents 87deee1 + a64f5ae commit fefdc8c

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

dbt/adapters/fabric/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = "1.9.1"
1+
version = "1.9.2"

dbt/include/fabric/macros/materializations/models/table/create_table_as.sql

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
1+
{% macro check_for_nested_cte(sql) %}
2+
{% if execute %} {# Ensure this runs only at execution time #}
3+
{% set cleaned_sql = sql | lower | replace("\n", " ") %} {# Convert to lowercase and remove newlines #}
4+
{% set cte_count = cleaned_sql.count("with ") %} {# Count occurrences of "WITH " #}
5+
{% if cte_count > 1 %}
6+
{{ return(True) }}
7+
{% else %}
8+
{{ return(False) }} {# No nested CTEs found #}
9+
{% endif %}
10+
{% else %}
11+
{{ return(False) }} {# Return False during parsing #}
12+
{% endif %}
13+
{% endmacro %}
14+
15+
116
{% macro fabric__create_table_as(temporary, relation, sql) -%}
217

318
{% set query_label = apply_label() %}
419
{% set contract_config = config.get('contract') %}
20+
{% set is_nested_cte = check_for_nested_cte(sql) %}
521

6-
{% if sql.strip().lower().startswith('with') and contract_config.enforced %}
22+
{% if is_nested_cte and contract_config.enforced %}
723

824
{{ exceptions.raise_compiler_error(
9-
"As contract is enforced and the model is using CTE, INSERT INTO is not supported with CTE. Either do not enforce contract or change the model"
25+
"Since the contract is enforced and the model contains a nested CTE, Fabric DW uses CREATE TABLE + INSERT to load data.
26+
INSERT INTO is not supported with nested CTEs. To resolve this, either disable contract enforcement or modify the model."
1027
) }}
1128

12-
{%- elif not sql.strip().lower().startswith('with') and contract_config.enforced %}
29+
{%- elif not is_nested_cte and contract_config.enforced %}
1330

1431
CREATE TABLE {{relation}}
1532
{{ build_columns_constraints(relation) }}

0 commit comments

Comments
 (0)