You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/12/15 16:18:22 UTC

[GitHub] [arrow] Dandandan commented on a change in pull request #8918: ARROW-10907: [Rust] Fix Cast UTF8 to Date64

Dandandan commented on a change in pull request #8918:
URL: https://github.com/apache/arrow/pull/8918#discussion_r543485838



##########
File path: rust/arrow/src/compute/kernels/cast.rs
##########
@@ -401,19 +401,18 @@ pub fn cast(array: &ArrayRef, to_type: &DataType) -> Result<ArrayRef> {
                 Ok(Arc::new(builder.finish()) as ArrayRef)
             }
             Date64(DateUnit::Millisecond) => {
-                use chrono::{NaiveDate, NaiveTime};
-                let zero_time = NaiveTime::from_hms(0, 0, 0);
+                use chrono::NaiveDateTime;
                 let string_array = array.as_any().downcast_ref::<StringArray>().unwrap();
                 let mut builder = PrimitiveBuilder::<Date64Type>::new(string_array.len());
                 for i in 0..string_array.len() {
                     if string_array.is_null(i) {
                         builder.append_null()?;
                     } else {
-                        match NaiveDate::parse_from_str(string_array.value(i), "%Y-%m-%d")
-                        {
-                            Ok(date) => builder.append_value(
-                                date.and_time(zero_time).timestamp_millis() as i64,
-                            )?,
+                        match NaiveDateTime::parse_from_str(
+                            string_array.value(i),

Review comment:
       See latest commits in #8913. There is a default parser that also avoids parsing the format for each value, and also supports the decimal fraction




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org