Skip to content

Commit ddd219c

Browse files
fix: dispatch render_value for Fabric boolean literal compatibility in INSERT VALUES
Co-Authored-By: Itamar Hartstein <haritamar@gmail.com>
1 parent 00715f1 commit ddd219c

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

macros/utils/table_operations/insert_rows.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@
283283
{%- endmacro -%}
284284
285285
{%- macro render_value(value, data_type) -%}
286+
{{- adapter.dispatch("render_value", "elementary")(value, data_type) -}}
287+
{%- endmacro -%}
288+
289+
{%- macro default__render_value(value, data_type) -%}
286290
{%- if value is defined and value is not none -%}
287291
{%- if value is number -%} {{- value -}}
288292
{%- elif value is string and data_type == "timestamp" -%}
@@ -299,3 +303,26 @@
299303
{%- else -%} null
300304
{%- endif -%}
301305
{%- endmacro -%}
306+
307+
{# Fabric/T-SQL: Python booleans (True/False) pass Jinja's "is number" test
308+
but T-SQL has no TRUE/FALSE keywords, so they must be rendered as
309+
cast(1 as bit) / cast(0 as bit). #}
310+
{%- macro fabric__render_value(value, data_type) -%}
311+
{%- if value is defined and value is not none -%}
312+
{%- if value is boolean -%}
313+
{%- if value -%} cast(1 as bit) {%- else -%} cast(0 as bit) {%- endif -%}
314+
{%- elif value is number -%} {{- value -}}
315+
{%- elif value is string and data_type == "timestamp" -%}
316+
{{-
317+
elementary.edr_cast_as_timestamp(
318+
elementary.edr_datetime_to_sql(value)
319+
)
320+
-}}
321+
{%- elif value is string -%} '{{- elementary.escape_special_chars(value) -}}'
322+
{%- elif value is mapping or value is sequence -%}
323+
'{{- elementary.escape_special_chars(tojson(value)) -}}'
324+
{%- else -%} null
325+
{%- endif -%}
326+
{%- else -%} null
327+
{%- endif -%}
328+
{%- endmacro -%}

0 commit comments

Comments
 (0)