From 40901a4eb1709cd08dbd084a52779acbea065df0 Mon Sep 17 00:00:00 2001 From: Serhii Dimchenko Date: Tue, 26 Sep 2023 00:03:20 +0200 Subject: [PATCH] Fixed listagg macro and functional tests --- dbt/include/athena/macros/utils/listagg.sql | 18 ++++++++++++++++++ dbt/include/athena/macros/utils/timestamps.sql | 3 ++- tests/functional/adapter/utils/test_utils.py | 13 ++++++------- 3 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 dbt/include/athena/macros/utils/listagg.sql diff --git a/dbt/include/athena/macros/utils/listagg.sql b/dbt/include/athena/macros/utils/listagg.sql new file mode 100644 index 00000000..265e1bd1 --- /dev/null +++ b/dbt/include/athena/macros/utils/listagg.sql @@ -0,0 +1,18 @@ +{% macro athena__listagg(measure, delimiter_text, order_by_clause, limit_num) -%} + array_join( + {%- if limit_num %} + slice( + {%- endif %} + array_agg( + {{ measure }} + {%- if order_by_clause %} + {{ order_by_clause }} + {%- endif %} + ) + {%- if limit_num %} + , 1, {{ limit_num }} + ) + {%- endif %} + , {{ delimiter_text }} + ) +{%- endmacro %} diff --git a/dbt/include/athena/macros/utils/timestamps.sql b/dbt/include/athena/macros/utils/timestamps.sql index d82dc541..bf220733 100644 --- a/dbt/include/athena/macros/utils/timestamps.sql +++ b/dbt/include/athena/macros/utils/timestamps.sql @@ -10,7 +10,8 @@ {% macro cast_timestamp(timestamp_col) -%} {%- set config = model.get('config', {}) -%} {%- set table_type = config.get('table_type', 'glue') -%} - {%- if table_type == 'iceberg' and not config.get('materialized', 'table') == 'view' -%} + {%- set is_view = config.get('materialized', 'table') == 'view' -%} + {%- if table_type == 'iceberg' and not is_view -%} cast({{ timestamp_col }} as timestamp(6)) {%- else -%} cast({{ timestamp_col }} as timestamp) diff --git a/tests/functional/adapter/utils/test_utils.py b/tests/functional/adapter/utils/test_utils.py index 83f743e9..ef13c062 100644 --- a/tests/functional/adapter/utils/test_utils.py +++ b/tests/functional/adapter/utils/test_utils.py @@ -15,6 +15,7 @@ from dbt.tests.adapter.utils.test_array_construct import BaseArrayConstruct from dbt.tests.adapter.utils.test_bool_or import BaseBoolOr 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_trunc import BaseDateTrunc from dbt.tests.adapter.utils.test_dateadd import BaseDateAdd from dbt.tests.adapter.utils.test_datediff import BaseDateDiff @@ -25,6 +26,7 @@ from dbt.tests.adapter.utils.test_hash import BaseHash from dbt.tests.adapter.utils.test_intersect import BaseIntersect from dbt.tests.adapter.utils.test_length import BaseLength +from dbt.tests.adapter.utils.test_listagg import BaseListagg from dbt.tests.adapter.utils.test_position import BasePosition from dbt.tests.adapter.utils.test_replace import BaseReplace from dbt.tests.adapter.utils.test_right import BaseRight @@ -181,9 +183,8 @@ def models(self): # pass -# TODO: Implement this macro when needed -# class TestListagg(BaseListagg): -# pass +class TestListagg(BaseListagg): + pass # TODO: Implement this macro when needed @@ -191,7 +192,5 @@ def models(self): # pass -# TODO: Right now this test is failing -# pyathena.error.OperationalError: NOT_SUPPORTED: Casting a Timestamp with Time Zone to Timestamp is not supported -# class TestCurrentTimestamp(BaseCurrentTimestampNaive): -# pass +class TestCurrentTimestamp(BaseCurrentTimestampNaive): + pass