Skip to content

Commit

Permalink
test: extend integration tests with more than 25 days
Browse files Browse the repository at this point in the history
  • Loading branch information
cverhoef committed Jan 4, 2024
1 parent 3c7f761 commit 5575050
Showing 2 changed files with 25 additions and 5 deletions.
9 changes: 9 additions & 0 deletions integration_tests/models/schema.yml
Original file line number Diff line number Diff line change
@@ -84,9 +84,18 @@ models:
- equal_value:
actual: '`add_years`'
expected: '`add_years_expected`'
- equal_value:
actual: '`add_30_days_in_days`'
expected: '`add_30_days_in_days_expected`'
- equal_value:
actual: '`add_30_days_in_seconds`'
expected: '`add_30_days_in_seconds_expected`'
- equal_value:
actual: '`add_bigint`'
expected: '`add_bigint_expected`'
- equal_value:
actual: '`add_bigint_30_days`'
expected: '`add_bigint_30_days_expected`'
- equal_value:
actual: '`add_to_null_value`'
expected: '`add_to_null_value_expected`'
21 changes: 16 additions & 5 deletions integration_tests/models/test_dateadd.sql
Original file line number Diff line number Diff line change
@@ -2,12 +2,12 @@ with Input_data as (
select
'2023-11-12 13:14:15.678' as `testdate`,
null as `null_value`,
{{ pm_utils.to_integer('1') }} as `bigint_value`

{{ pm_utils.to_integer('1') }} as `bigint_value`,
{{ pm_utils.to_integer('30') }} as `bigint_value_30`,
)

select
{# Add milliseconds, seconds, minutes, hours, days, months and years #}
{# Add 1 unit for every possible dateparts. #}
{{ pm_utils.to_varchar(pm_utils.dateadd('millisecond', 1, '`testdate`')) }} as `add_milliseconds`,
{{ pm_utils.to_varchar(pm_utils.dateadd('second', 1, '`testdate`')) }} as `add_seconds`,
{{ pm_utils.to_varchar(pm_utils.dateadd('minute', 1, '`testdate`')) }} as `add_minutes`,
@@ -18,8 +18,13 @@ select
{{ pm_utils.to_varchar(pm_utils.dateadd('quarter', 1, '`testdate`')) }} as `add_quarters`,
{{ pm_utils.to_varchar(pm_utils.dateadd('year', 1, '`testdate`')) }} as `add_years`,

{# Use bigint as the value #}
{{ pm_utils.to_varchar(pm_utils.dateadd('year', '`bigint_value`', '`testdate`')) }} as `add_bigint`,
{# Add 30 days to cover the scenario a bigint is required to store the amount of milliseconds. #}
{{ pm_utils.to_varchar(pm_utils.dateadd('day', 30, '`testdate`')) }} as `add_30_days_in_days`,
{{ pm_utils.to_varchar(pm_utils.dateadd('second', 2592000, '`testdate`')) }} as `add_30_days_in_seconds`,

{# Use a bigint datatype as the input for number of units to be added. #}
{{ pm_utils.to_varchar(pm_utils.dateadd('year', '`bigint_value`', '`testdate`')) }} as `add_bigint`,
{{ pm_utils.to_varchar(pm_utils.dateadd('day', '`bigint_value_30`', '`testdate`')) }} as `add_bigint_30_days`,

{% if target.type == 'sqlserver' %}
{# SQL Server uses datetime2 format, which has a precision of 7 digits #}
@@ -32,7 +37,10 @@ select
'2023-12-12 13:14:15.6780000' as `add_months_expected`,
'2024-02-12 13:14:15.6780000' as `add_quarters_expected`,
'2024-11-12 13:14:15.6780000' as `add_years_expected`,
'2023-12-12 13:14:15.6780000' as `add_30_days_in_days_expected`,
'2023-12-12 13:14:15.6780000' as `add_30_days_in_seconds_expected`,
'2024-11-12 13:14:15.6780000' as `add_bigint_expected`,
'2023-12-12 13:14:15.6780000' as `add_bigint_30_days_expected`,
{% else %}
'2023-11-12 13:14:15.679' as `add_milliseconds_expected`,
'2023-11-12 13:14:16.678' as `add_seconds_expected`,
@@ -43,7 +51,10 @@ select
'2023-12-12 13:14:15.678' as `add_months_expected`,
'2024-02-12 13:14:15.678' as `add_quarters_expected`,
'2024-11-12 13:14:15.678' as `add_years_expected`,
'2023-12-12 13:14:15.678' as `add_30_days_in_days_expected`,
'2023-12-12 13:14:15.678' as `add_30_days_in_seconds_expected`,
'2024-11-12 13:14:15.678' as `add_bigint_expected`,
'2023-12-12 13:14:15.678' as `add_bigint_30_days_expected`,
{% endif %}

{# Use null as the date #}

0 comments on commit 5575050

Please sign in to comment.