Skip to content

Commit 186f398

Browse files
authored
add casting feature to insert_list_to_table and utilize it for run_at in save_results_history (#88)
1 parent e049f33 commit 186f398

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

macros/run_end/save_results_history.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
{% do re_data.insert_list_to_table(
2121
ref('re_data_test_history'),
2222
tests,
23-
['table_name', 'column_name', 'test_name', 'status', 'execution_time', 'message', 'failures_count', 'failures_json', 'failures_table', 'severity', 'compiled_sql', 'run_at']
23+
['table_name', 'column_name', 'test_name', 'status', 'execution_time', 'message', 'failures_count', 'failures_json', 'failures_table', 'severity', 'compiled_sql', 'run_at'],
24+
{ 'run_at': timestamp_type() }
2425
) %}
2526
{% endif %}
2627

@@ -108,4 +109,4 @@
108109

109110
{{ return(none) }}
110111

111-
{% endmacro %}
112+
{% endmacro %}

macros/store/insert_list_to_table.sql

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% macro insert_list_to_table(table, list, params, insert_size=100) %}
1+
{% macro insert_list_to_table(table, list, params, dtype=None,insert_size=100) %}
22

33
{% set single_insert_list = [] %}
44
{% for el in list %}
@@ -15,7 +15,12 @@
1515
NULL
1616
{%- else -%}
1717
{%- if row[p] is string -%}
18-
{{- re_data.quote_string(row[p]) -}}
18+
{%- if dtype and p in dtype -%}
19+
{% set cast_type = dtype[p] %}
20+
cast ({{ re_data.quote_string(row[p]) }} as {{ cast_type }})
21+
{%- else %}
22+
{{- re_data.quote_string(row[p]) -}}
23+
{%- endif -%}
1924
{%- elif row[p] is number -%}
2025
{{-row[p]-}}
2126
{%- else -%}
@@ -34,4 +39,4 @@
3439
{% endif %}
3540
{% endfor %}
3641

37-
{% endmacro %}
42+
{% endmacro %}

0 commit comments

Comments
 (0)