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 2022/04/12 13:33:51 UTC

[GitHub] [arrow-rs] alamb commented on a diff in pull request #1534: Enable Date32/64 to String/LargeString cast

alamb commented on code in PR #1534:
URL: https://github.com/apache/arrow-rs/pull/1534#discussion_r848442168


##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -1300,6 +1306,44 @@ where
     ))
 }
 
+/// Cast date32 types to Utf8/LargeUtf8
+fn cast_date32_to_string<OffsetSize: StringOffsetSizeTrait>(
+    array: &ArrayRef,
+) -> Result<ArrayRef> {
+    let array = array.as_any().downcast_ref::<Date32Array>().unwrap();
+
+    Ok(Arc::new(
+        (0..array.len())
+            .map(|ix| {
+                if array.is_null(ix) {
+                    None
+                } else {
+                    array.value_as_date(ix).map(|v| v.to_string())
+                }
+            })
+            .collect::<GenericStringArray<OffsetSize>>(),
+    ))

Review Comment:
   It would be cool tou se `iter()` on the array which would be faster and more idomatic. However I see there is no great way to call `value_as_date()` without an `Date32Array`



-- 
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-unsubscribe@arrow.apache.org

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