Skip to content

Commit

Permalink
Fixed listagg macro and functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
svdimchenko committed Sep 25, 2023
1 parent 5401574 commit 40901a4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
18 changes: 18 additions & 0 deletions dbt/include/athena/macros/utils/listagg.sql
Original file line number Diff line number Diff line change
@@ -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 %}
3 changes: 2 additions & 1 deletion dbt/include/athena/macros/utils/timestamps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 6 additions & 7 deletions tests/functional/adapter/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -181,17 +183,14 @@ def models(self):
# pass


# TODO: Implement this macro when needed
# class TestListagg(BaseListagg):
# pass
class TestListagg(BaseListagg):
pass


# TODO: Implement this macro when needed
# class TestLastDay(BaseLastDay):
# 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

0 comments on commit 40901a4

Please sign in to comment.