This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new cb88a79a1a fix: parsing timestamp with date format (#10476)
cb88a79a1a is described below

commit cb88a79a1aeffbe543778da41c27d9c363be4dad
Author: shanretoo <[email protected]>
AuthorDate: Thu May 16 01:42:01 2024 +0800

    fix: parsing timestamp with date format (#10476)
    
    * fix parsing timestamp with date format
    
    * add test in dates.slt
---
 datafusion/functions/src/datetime/common.rs       | 4 +++-
 datafusion/functions/src/datetime/to_timestamp.rs | 4 ++++
 datafusion/sqllogictest/test_files/dates.slt      | 6 ++++++
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/datafusion/functions/src/datetime/common.rs 
b/datafusion/functions/src/datetime/common.rs
index f0689ffd64..4f48ab1884 100644
--- a/datafusion/functions/src/datetime/common.rs
+++ b/datafusion/functions/src/datetime/common.rs
@@ -93,7 +93,9 @@ pub(crate) fn string_to_datetime_formatted<T: TimeZone>(
 
     if let Err(e) = &dt {
         // no timezone or other failure, try without a timezone
-        let ndt = parsed.to_naive_datetime_with_offset(0);
+        let ndt = parsed
+            .to_naive_datetime_with_offset(0)
+            .or_else(|_| parsed.to_naive_date().map(|nd| nd.into()));
         if let Err(e) = &ndt {
             return Err(err(&e.to_string()));
         }
diff --git a/datafusion/functions/src/datetime/to_timestamp.rs 
b/datafusion/functions/src/datetime/to_timestamp.rs
index a7bcca6294..af878b4505 100644
--- a/datafusion/functions/src/datetime/to_timestamp.rs
+++ b/datafusion/functions/src/datetime/to_timestamp.rs
@@ -670,6 +670,10 @@ mod tests {
             parse_timestamp_formatted("09-08-2020 13/42/29", "%m-%d-%Y 
%H/%M/%S")
                 .unwrap()
         );
+        assert_eq!(
+            1642896000000000000,
+            parse_timestamp_formatted("2022-01-23", "%Y-%m-%d").unwrap()
+        );
     }
 
     fn parse_timestamp_formatted(s: &str, format: &str) -> Result<i64, 
DataFusionError> {
diff --git a/datafusion/sqllogictest/test_files/dates.slt 
b/datafusion/sqllogictest/test_files/dates.slt
index 32c0bd14e7..e21637bd89 100644
--- a/datafusion/sqllogictest/test_files/dates.slt
+++ b/datafusion/sqllogictest/test_files/dates.slt
@@ -224,5 +224,11 @@ SELECT to_date(t.ts, '%Y-%m-%d %H/%M/%S%#z', '%s', '%q', 
'%d-%m-%Y %H:%M:%S%#z',
 query error function unsupported data type at index 1:
 SELECT to_date(t.ts, make_array('%Y-%m-%d %H/%M/%S%#z', '%s', '%q', '%d-%m-%Y 
%H:%M:%S%#z', '%+')) from ts_utf8_data as t
 
+# verify to_date with format
+query D
+select to_date('2022-01-23', '%Y-%m-%d');
+----
+2022-01-23
+
 statement ok
 drop table ts_utf8_data


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to