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" 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 a3a8173b..ab103f84 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 -%} {{ validate_fixture_rows(rows, row_number) }}