alamb commented on code in PR #9019: URL: https://github.com/apache/arrow-datafusion/pull/9019#discussion_r1476758593
########## datafusion/physical-expr/src/datetime_expressions.rs: ########## @@ -1337,6 +1376,36 @@ fn validate_to_timestamp_data_types( None } +/// to_date SQL function implementation +pub fn to_date_invoke(args: &[ColumnarValue]) -> Result<ColumnarValue> { + if args.is_empty() { + return exec_err!( + "to_date function requires 1 or more arguments, got {}", + args.len() + ); + } + + // validate that any args after the first one are Utf8 + if args.len() > 1 { + if let Some(value) = validate_to_timestamp_data_types(args, "to_date") { + return value; + } + } + + match args[0].data_type() { + DataType::Int32 Review Comment: It looks like your code takes several input types -- can you please add tests that show calling `to_date` with these types (eg `select to_date(arrow_cast(123, 'Int64'))`) ########## datafusion/sqllogictest/test_files/dates.slt: ########## @@ -107,3 +107,27 @@ query ? SELECT '2023-01-01T00:00:00'::timestamp - DATE '2021-01-01'; ---- 730 days 0 hours 0 mins 0.000000000 secs + +# to_date_test +statement ok +create table to_date_t1(ts bigint) as VALUES + (1235865600000), + (1235865660000), + (1238544000000); + + +# query_cast_timestamp_millis +query D +SELECT to_date(ts / 100000000) FROM to_date_t1 LIMIT 3 +---- +2003-11-02 +2003-11-02 +2003-11-29 + +query D +SELECT to_date('01-14-2023 01:01:30+05:30', '%q', '%d-%m-%Y %H/%M/%S', '%+', '%m-%d-%Y %H:%M:%S%#z'); +---- +2023-01-13 + +statement error DataFusion error: Internal error: to_date function unsupported data type at index 1: List +SELECT to_date('2022-08-03T14:38:50+05:30', make_array('%s', '%q', '%d-%m-%Y %H:%M:%S%#z', '%+')); Review Comment: Can we also please add a test for invalid dates like ``` to_date('21311111') ``` I think the tests here could be copied and adapted to cover `to_date` quite well: https://github.com/apache/arrow-datafusion/blob/7641a3228156aab0e48c4bab5a6834b44f722d89/datafusion/sqllogictest/test_files/timestamps.slt#L2073-L2229 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org