diff --git a/.changes/unreleased/Features-20240501-151904.yaml b/.changes/unreleased/Features-20240501-151904.yaml new file mode 100644 index 000000000..ed08f1251 --- /dev/null +++ b/.changes/unreleased/Features-20240501-151904.yaml @@ -0,0 +1,6 @@ +kind: Features +body: Cross-database `date` macro +time: 2024-05-01T15:19:04.822157-06:00 +custom: + Author: dbeatty10 + Issue: 1031 diff --git a/dbt/include/spark/macros/utils/date.sql b/dbt/include/spark/macros/utils/date.sql new file mode 100644 index 000000000..a76e995b3 --- /dev/null +++ b/dbt/include/spark/macros/utils/date.sql @@ -0,0 +1,5 @@ +{% macro spark__date(year, month, day) -%} + {%- set dt = modules.datetime.date(year, month, day) -%} + {%- set iso_8601_formatted_date = dt.strftime('%Y-%m-%d') -%} + to_date('{{ iso_8601_formatted_date }}', 'yyyy-MM-dd') +{%- endmacro %} diff --git a/tests/functional/adapter/utils/test_utils.py b/tests/functional/adapter/utils/test_utils.py index 0dc526564..e8ebb087f 100644 --- a/tests/functional/adapter/utils/test_utils.py +++ b/tests/functional/adapter/utils/test_utils.py @@ -8,6 +8,7 @@ from dbt.tests.adapter.utils.test_cast_bool_to_text import BaseCastBoolToText from dbt.tests.adapter.utils.test_concat import BaseConcat from dbt.tests.adapter.utils.test_current_timestamp import BaseCurrentTimestampNaive +from dbt.tests.adapter.utils.test_date import BaseDate from dbt.tests.adapter.utils.test_dateadd import BaseDateAdd from dbt.tests.adapter.utils.test_datediff import BaseDateDiff from dbt.tests.adapter.utils.test_date_trunc import BaseDateTrunc @@ -80,6 +81,10 @@ class TestCurrentTimestamp(BaseCurrentTimestampNaive): pass +class TestDate(BaseDate): + pass + + class TestDateAdd(BaseDateAdd): pass