File tree Expand file tree Collapse file tree 2 files changed +21
-4
lines changed
include/fabric/macros/materializations/models/table Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change 1- version = "1.9.1 "
1+ version = "1.9.2 "
Original file line number Diff line number Diff line change 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) }}
You can’t perform that action at this time.
0 commit comments