From 048e7579f5bc4db23350c016b2f4ee853108f865 Mon Sep 17 00:00:00 2001 From: Dennis-UiPath Date: Thu, 23 Nov 2023 09:02:11 +0100 Subject: [PATCH] test(integration) add test for dateadd --- integration_tests/models/schema.yml | 36 +++++++++++++++ integration_tests/models/test_dateadd.sql | 53 +++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 integration_tests/models/test_dateadd.sql diff --git a/integration_tests/models/schema.yml b/integration_tests/models/schema.yml index 38c322b..b7f714a 100644 --- a/integration_tests/models/schema.yml +++ b/integration_tests/models/schema.yml @@ -54,3 +54,39 @@ models: - equal_value: actual: '`null_value`' expected: '`null_value_expected`' + + - name: test_dateadd + tests: + - equal_value: + actual: '`add_milliseconds`' + expected: '`add_milliseconds_expected`' + - equal_value: + actual: '`add_seconds`' + expected: '`add_seconds_expected`' + - equal_value: + actual: '`add_minutes`' + expected: '`add_minutes_expected`' + - equal_value: + actual: '`add_hours`' + expected: '`add_hours_expected`' + - equal_value: + actual: '`add_days`' + expected: '`add_days_expected`' + - equal_value: + actual: '`add_weeks`' + expected: '`add_weeks_expected`' + - equal_value: + actual: '`add_months`' + expected: '`add_months_expected`' + - equal_value: + actual: '`add_quarters`' + expected: '`add_quarters_expected`' + - equal_value: + actual: '`add_years`' + expected: '`add_years_expected`' + - equal_value: + actual: '`add_bigint`' + expected: '`add_bigint_expected`' + - equal_value: + actual: '`add_to_null_value`' + expected: '`add_to_null_value_expected`' diff --git a/integration_tests/models/test_dateadd.sql b/integration_tests/models/test_dateadd.sql new file mode 100644 index 0000000..b82a906 --- /dev/null +++ b/integration_tests/models/test_dateadd.sql @@ -0,0 +1,53 @@ +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` + +) + +select + {# Add milliseconds, seconds, minutes, hours, days, months and years #} + {{ 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`, + {{ pm_utils.to_varchar(pm_utils.dateadd('hour', 1, '`testdate`')) }} as `add_hours`, + {{ pm_utils.to_varchar(pm_utils.dateadd('day', 1, '`testdate`')) }} as `add_days`, + {{ pm_utils.to_varchar(pm_utils.dateadd('week', 1, '`testdate`')) }} as `add_weeks`, + {{ pm_utils.to_varchar(pm_utils.dateadd('month', 1, '`testdate`')) }} as `add_months`, + {{ 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`, + + {% if target.type == 'sqlserver' %} + {# SQL Server uses datetime2 format, which has a precision of 7 digits #} + '2023-11-12 13:14:15.6790000' as `add_milliseconds_expected`, + '2023-11-12 13:14:16.6780000' as `add_seconds_expected`, + '2023-11-12 13:15:15.6780000' as `add_minutes_expected`, + '2023-11-12 14:14:15.6780000' as `add_hours_expected`, + '2023-11-13 13:14:15.6780000' as `add_days_expected`, + '2023-11-19 13:14:15.6780000' as `add_weeks_expected`, + '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`, + '2024-11-12 13:14:15.6780000' as `add_bigint_expected`, + {% else %} + '2023-11-12 13:14:15.679' as `add_milliseconds_expected`, + '2023-11-12 13:14:16.678' as `add_seconds_expected`, + '2023-11-12 13:15:15.678' as `add_minutes_expected`, + '2023-11-12 14:14:15.678' as `add_hours_expected`, + '2023-11-13 13:14:15.678' as `add_days_expected`, + '2023-11-19 13:14:15.678' as `add_weeks_expected`, + '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`, + '2024-11-12 13:14:15.678' as `add_bigint_expected`, + {% endif %} + + {# Use null as the date #} + {{ pm_utils.to_varchar(pm_utils.dateadd('year', 1, '`null_value`')) }} as `add_to_null_value`, + '' as `add_to_null_value_expected` + +from Input_data