File tree 2 files changed +21
-4
lines changed
include/fabric/macros/materializations/models/table
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
+
1
16
{% macro fabric__create_table_as(temporary, relation, sql) - %}
2
17
3
18
{% set query_label = apply_label() %}
4
19
{% set contract_config = config .get (' contract' ) %}
20
+ {% set is_nested_cte = check_for_nested_cte(sql) %}
5
21
6
- {% if sql . strip (). lower ().startswith( ' with ' ) and contract_config .enforced %}
22
+ {% if is_nested_cte and contract_config .enforced %}
7
23
8
24
{{ 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."
10
27
) }}
11
28
12
- {%- elif not sql . strip (). lower ().startswith( ' with ' ) and contract_config .enforced %}
29
+ {%- elif not is_nested_cte and contract_config .enforced %}
13
30
14
31
CREATE TABLE {{relation}}
15
32
{{ build_columns_constraints(relation) }}
You can’t perform that action at this time.
0 commit comments