Skip to content

Commit

Permalink
Dupport quarter in postgres last day (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
seunghanhong authored and clrcrl committed May 18, 2021
1 parent 6932957 commit c47ccd1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
* Add new schema test, `not_accepted_values` ([#284](https://github.com/fishtown-analytics/dbt-utils/pull/284) [@JavierMonton](https://github.com/JavierMonton))
* Support a new argument, `zero_length_range_allowed` in the `mutually_exclusive_ranges` test ([#307](https://github.com/fishtown-analytics/dbt-utils/pull/307) [@zemekeng](https://github.com/zemekeneng))
* Add new schema test, `sequential_values` ([#318](https://github.com/fishtown-analytics/dbt-utils/pull/318), inspired by [@hundredwatt](https://github.com/hundredwatt))
* Support `quarter` in the `postgres__last_day` macro ([#333](https://github.com/fishtown-analytics/dbt-utils/pull/333/files), [@seunghanhong](https://github.com/seunghanhong))


## Fixes
* Handle booleans gracefully in the unpivot macro ([#305](https://github.com/fishtown-analytics/dbt-utils/pull/305) [@avishalom](https://github.com/avishalom))
* Fix a bug in `get_relation_by_prefix` that happens with Snowflake external tables. Now the macro will retrieve tables that match the prefix which are external tables ([#350](https://github.com/fishtown-analytics/dbt-utils/issues/350))

## Under the hood


Expand Down
1 change: 1 addition & 0 deletions integration_tests/data/cross_db/data_last_day.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
date_day,date_part,result
2018-01-02,month,2018-01-31
2018-01-02,quarter,2018-03-31
2018-01-02,year,2018-12-31
,month,
1 change: 1 addition & 0 deletions integration_tests/models/cross_db_utils/test_last_day.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ with data as (
select
case
when date_part = 'month' then {{ dbt_utils.last_day('date_day', 'month') }}
when date_part = 'quarter' then {{ dbt_utils.last_day('date_day', 'quarter') }}
when date_part = 'year' then {{ dbt_utils.last_day('date_day', 'year') }}
else null
end as actual,
Expand Down
8 changes: 6 additions & 2 deletions macros/cross_db_utils/last_day.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ testing is required to validate that it will work on other dateparts.
{% macro postgres__last_day(date, datepart) -%}

{%- if datepart == 'quarter' -%}
{{ exceptions.raise_compiler_error(
"dbt_utils.last_day is not supported for datepart 'quarter' on this adapter") }}
-- postgres dateadd does not support quarter interval.
cast(
{{dbt_utils.dateadd('day', '-1',
dbt_utils.dateadd('month', '3', dbt_utils.date_trunc(datepart, date))
)}}
as date)
{%- else -%}
{{dbt_utils.default_last_day(date, datepart)}}
{%- endif -%}
Expand Down

0 comments on commit c47ccd1

Please sign in to comment.