From dbbaded0c58ab3ddaef743b76ce1ccb9820d872a Mon Sep 17 00:00:00 2001 From: Bruce Ritchie <bruce.ritchie@veeva.com> Date: Fri, 9 Feb 2024 08:04:57 -0500 Subject: [PATCH] adding sqllogictests --- .../sqllogictest/test_files/timestamps.slt | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/datafusion/sqllogictest/test_files/timestamps.slt b/datafusion/sqllogictest/test_files/timestamps.slt index 980545e922c4..ba8a56dcf197 100644 --- a/datafusion/sqllogictest/test_files/timestamps.slt +++ b/datafusion/sqllogictest/test_files/timestamps.slt @@ -2565,3 +2565,86 @@ select make_date(2024, 1, null); query error DataFusion error: Arrow error: Cast error: Cannot cast string '' to value of Int32 type select make_date(2024, 1, ''); + + +########## +## to_char tests +########## + +statement ok +create table formats ( + dates date, + timestamps timestamp, + date_format varchar, + timestamp_format varchar) +as values + ('2000-01-01'::date, '2024-01-01 06:00:00'::timestamp, '%d:%m:%Y', '%d:%m:%Y %H-%M-%S'), + ('2003-04-05'::date, '2025-01-01 23:59:58'::timestamp, '%d:%m:%Y', '%d:%m:%Y %H-%M-%S'); + + +query T +select to_char(dates, date_format) from formats; +---- +01:01:2000 +05:04:2003 + +query T +select date_format(dates, date_format) from formats; +---- +01:01:2000 +05:04:2003 + +query T +select to_char(timestamps, date_format) from formats; +---- +01:01:2024 +01:01:2025 + +query T +select to_char(timestamps, timestamp_format) from formats; +---- +01:01:2024 06-00-00 +01:01:2025 23-59-58 + +query T +select to_char('2000-02-03'::date, '%Y:%d:%m'); +---- +2000:03:02 + +query T +select to_char(arrow_cast(TIMESTAMP '2023-08-03 14:38:50Z', 'Timestamp(Second, None)'), '%d-%m-%Y %H-%M-%S') +---- +03-08-2023 14-38-50 + +query T +select to_char(arrow_cast(123456, 'Duration(Second)'), 'pretty'); +---- +1 days 10 hours 17 mins 36 secs + +query T +select to_char(arrow_cast(123456, 'Duration(Second)'), 'iso8601'); +---- +P1DT37056S + +query T +select to_char(arrow_cast(123456, 'Duration(Second)'), null); +---- +1 days 10 hours 17 mins 36 secs + +# this panics with a unhandled internal error in arrow-rs code +#query error +#SELECT to_char(timestamps, '%X%K') from formats; + +query T +SELECT to_char(timestamps, null) from formats; +---- +(empty) +(empty) + +query T +SELECT to_char(null, '%d-%m-%Y'); +---- +(empty) + +statement ok +drop table formats;