From e6e079cd1dea498c2b0f57d6d0b5cf90418cc62a Mon Sep 17 00:00:00 2001 From: Steffen Galan Date: Mon, 15 Jul 2024 20:39:45 +0200 Subject: [PATCH 1/2] Add macro to allow adapter-specific choice of unspecified value --- .../macros/relations/column/columns_spec_ddl.sql | 8 ++++++++ .../macros/unit_test_sql/get_fixture_sql.sql | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/dbt/include/global_project/macros/relations/column/columns_spec_ddl.sql b/dbt/include/global_project/macros/relations/column/columns_spec_ddl.sql index 7a56d09e..0faf9d0b 100644 --- a/dbt/include/global_project/macros/relations/column/columns_spec_ddl.sql +++ b/dbt/include/global_project/macros/relations/column/columns_spec_ddl.sql @@ -87,3 +87,11 @@ {% set formatted = column.column.lower() ~ " " ~ data_type %} {{ return({'name': column.name, 'data_type': data_type, 'formatted': formatted}) }} {%- endmacro -%} + +{% macro render_unspecified_column_value(column_type) %} + {{ return(adapter.dispatch('render_unspecified_column_value', 'dbt') (column_type)) }} +{% endmacro %} + +{% macro default__render_unspecified_column_value(column_type) %} + safe_cast('null', {{column_type}}) +{% endmacro %} diff --git a/dbt/include/global_project/macros/unit_test_sql/get_fixture_sql.sql b/dbt/include/global_project/macros/unit_test_sql/get_fixture_sql.sql index c25a87f7..2eb124e2 100644 --- a/dbt/include/global_project/macros/unit_test_sql/get_fixture_sql.sql +++ b/dbt/include/global_project/macros/unit_test_sql/get_fixture_sql.sql @@ -19,7 +19,7 @@ {%- endif -%} {%- for column_name, column_type in column_name_to_data_types.items() -%} - {%- do default_row.update({column_name: (safe_cast("null", column_type) | trim )}) -%} + {%- do default_row.update({column_name: (render_unspecified_column_value(column_type) | trim )}) -%} {%- endfor -%} From e29b1041058f501c7fca4e71bbaa8c23818cf118 Mon Sep 17 00:00:00 2001 From: Steffen Galan Date: Mon, 15 Jul 2024 20:59:37 +0200 Subject: [PATCH 2/2] Added change log entry --- .changes/unreleased/Features-20240715-205845.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Features-20240715-205845.yaml diff --git a/.changes/unreleased/Features-20240715-205845.yaml b/.changes/unreleased/Features-20240715-205845.yaml new file mode 100644 index 00000000..3bdb6ef1 --- /dev/null +++ b/.changes/unreleased/Features-20240715-205845.yaml @@ -0,0 +1,6 @@ +kind: Features +body: Added macro to allow adapter-specific choice of unspecified value in unit tests +time: 2024-07-15T20:58:45.587529+02:00 +custom: + Author: steffen030 + Issue: "10447"