Skip to content

Commit

Permalink
test(integration) add test to_timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis-UiPath committed Nov 23, 2023
1 parent 9dddab1 commit 016ab1b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
23 changes: 22 additions & 1 deletion integration_tests/models/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,25 @@ models:
expected: '`Find_empty_value_expected`'
- equal_value:
actual: '`Find_null_value`'
expected: '`Find_null_value_expected`'
expected: '`Find_null_value_expected`'

- name: test_to_timestamp
tests:
- equal_value:
actual: '`timestamp_date`'
expected: '`timestamp_date_expected`'
- equal_value:
actual: '`timestamp_datetime`'
expected: '`timestamp_datetime_expected`'
- equal_value:
actual: '`timestamp_datetime_ms`'
expected: '`timestamp_datetime_ms_expected`'
- equal_value:
actual: '`timestamp_datetime_ms4`'
expected: '`timestamp_datetime_ms4_expected`'
- equal_value:
actual: '`timestamp_time`'
expected: '`timestamp_time_expected`'
- equal_value:
actual: '`null_value`'
expected: '`null_value_expected`'
44 changes: 44 additions & 0 deletions integration_tests/models/test_to_timestamp.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
with Input_data as (
select
'2023-11-12' as `timestamp_date`,
'2023-11-12 13:14:15' as `timestamp_datetime`,
'2023-11-12 13:14:15.678' as `timestamp_datetime_ms`,
'2023-11-12 13:14:15.6789' as `timestamp_datetime_ms4`,
'13:14:15' as `timestamp_time`,
null as `null_value`
)

select
{{ pm_utils.to_varchar(pm_utils.to_timestamp('`timestamp_date`')) }} as `timestamp_date`,
{{ pm_utils.to_varchar(pm_utils.to_timestamp('`timestamp_datetime`')) }} as `timestamp_datetime`,
{{ pm_utils.to_varchar(pm_utils.to_timestamp('`timestamp_datetime_ms`')) }} as `timestamp_datetime_ms`,
{{ pm_utils.to_varchar(pm_utils.to_timestamp('`timestamp_datetime_ms4`')) }} as `timestamp_datetime_ms4`,
{{ pm_utils.to_varchar(pm_utils.to_timestamp('`timestamp_time`')) }} as `timestamp_time`,
{{ pm_utils.to_varchar(pm_utils.to_timestamp('`null_value`')) }} as `null_value`,

{% if target.type == 'databricks' %}
'' as `timestamp_date_expected`,
'2023-11-12 13:14:15' as `timestamp_datetime_expected`,
'2023-11-12 13:14:15.678' as `timestamp_datetime_ms_expected`,
'2023-11-12 13:14:15' as `timestamp_datetime_ms4_expected`,
'' as `timestamp_time_expected`,
'' as `null_value_expected`
{% elif target.type == 'sqlserver' %}
--SQL Server uses datetime2 format and always specifies the precision with 7 digits.
--SQL Server will also give a result when only having a date or a time as input
'2023-11-12 00:00:00.0000000' as `timestamp_date_expected`,
'2023-11-12 13:14:15.0000000' as `timestamp_datetime_expected`,
'2023-11-12 13:14:15.6780000' as `timestamp_datetime_ms_expected`,
'2023-11-12 13:14:15.6789000' as `timestamp_datetime_ms4_expected`,
'1900-01-01 13:14:15.0000000' as `timestamp_time_expected`,
'' as `null_value_expected`
{% elif target.type == 'snowflake' %}
'' as `timestamp_date_expected`,
'2023-11-12 13:14:15.000' as `timestamp_datetime_expected`,
'2023-11-12 13:14:15.678' as `timestamp_datetime_ms_expected`,
'2023-11-12 13:14:15.678' as `timestamp_datetime_ms4_expected`,
'' as `timestamp_time_expected`,
'' as `null_value_expected`
{% endif %}

from Input_data

0 comments on commit 016ab1b

Please sign in to comment.