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/08/30 06:00:56 UTC

[GitHub] [arrow-rs] viirya opened a new pull request, #2608: Cast timestamp array to string array with timezone

viirya opened a new pull request, #2608:
URL: https://github.com/apache/arrow-rs/pull/2608

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #2607.
   
   # Rationale for this change
    
   <!--
   Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
   -->
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!---
   If there are any breaking changes to public APIs, please add the `breaking change` label.
   -->
   


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


[GitHub] [arrow-rs] viirya commented on pull request #2608: Cast timestamp array to string array with timezone

Posted by GitBox <gi...@apache.org>.
viirya commented on PR #2608:
URL: https://github.com/apache/arrow-rs/pull/2608#issuecomment-1231182264

   cc @sunchao 


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


[GitHub] [arrow-rs] viirya commented on a diff in pull request #2608: Cast timestamp array to string array with timezone

Posted by GitBox <gi...@apache.org>.
viirya commented on code in PR #2608:
URL: https://github.com/apache/arrow-rs/pull/2608#discussion_r960034963


##########
arrow/src/compute/kernels/mod.rs:
##########
@@ -35,5 +35,6 @@ pub mod sort;
 pub mod substring;
 pub mod take;
 pub mod temporal;
+// pub(crate) use temporal::extract_component_from_array;

Review Comment:
   Oops, forgot to remove. This was left during debugging.



##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -1482,25 +1487,35 @@ where
 }
 
 /// Cast timestamp types to Utf8/LargeUtf8
-fn cast_timestamp_to_string<T, OffsetSize>(array: &ArrayRef) -> Result<ArrayRef>
+fn cast_timestamp_to_string<T, OffsetSize>(
+    array: &ArrayRef,
+    tz: &Option<String>,
+) -> Result<ArrayRef>
 where
     T: ArrowTemporalType + ArrowNumericType,
     i64: From<<T as ArrowPrimitiveType>::Native>,
     OffsetSize: OffsetSizeTrait,
 {
     let array = array.as_any().downcast_ref::<PrimitiveArray<T>>().unwrap();
 
-    Ok(Arc::new(
-        (0..array.len())
-            .map(|ix| {
-                if array.is_null(ix) {
-                    None
-                } else {
-                    array.value_as_datetime(ix).map(|v| v.to_string())
-                }
-            })
-            .collect::<GenericStringArray<OffsetSize>>(),
-    ))
+    let mut builder = GenericStringBuilder::<OffsetSize>::new();
+
+    if let Some(tz) = tz {
+        let mut scratch = Parsed::new();
+        extract_component_from_array!(

Review Comment:
   sure.



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


[GitHub] [arrow-rs] viirya commented on a diff in pull request #2608: Cast timestamp array to string array with timezone

Posted by GitBox <gi...@apache.org>.
viirya commented on code in PR #2608:
URL: https://github.com/apache/arrow-rs/pull/2608#discussion_r960034640


##########
arrow/src/compute/kernels/temporal.rs:
##########
@@ -28,33 +28,33 @@ use chrono::format::{parse, Parsed};
 use chrono::FixedOffset;
 
 macro_rules! extract_component_from_array {
-    ($array:ident, $builder:ident, $extract_fn:ident, $using:ident) => {
+    ($array:ident, $builder:ident, $extract_fn:ident, $using:ident, $convert:expr) => {

Review Comment:
   The result type of `hour` etc is Int32Array, but these APIs of `Timelike` (`hour`, `minute`, `second` etc) return u32. Previously in this macro, it is hardcoded as something like `dt.$extract_fn() as i32`. But for `to_string` API that is called for `cast` kernel, we don't need any conversion. In order to reuse this macro, I add this `$convert` to extract `as i32` part.



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


[GitHub] [arrow-rs] ursabot commented on pull request #2608: Cast timestamp array to string array with timezone

Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #2608:
URL: https://github.com/apache/arrow-rs/pull/2608#issuecomment-1233855231

   Benchmark runs are scheduled for baseline = f9a309445550e596e32a0dbf29879946f44c1dc6 and contender = 12ad8d71ace0624812215766e8e6b71272fa4598. 12ad8d71ace0624812215766e8e6b71272fa4598 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/dd78c5534cd34c1c9cdd4593966ec34b...9f5bd9fc67d64cc6aceb033c7d53ed39/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/1f6d5f5724f34588b7f5e7d73b36eb0e...21a3834f6a1b4547aaa66f052cb0def8/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/96f808ad5223498b9649d5cac75fbc76...de3a3c3531414ec095bd3be59503435a/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/c52b3d02dfd64eed86686b1126f540f6...62d9774865444f6b90e26a4e65faba42/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


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


[GitHub] [arrow-rs] viirya merged pull request #2608: Cast timestamp array to string array with timezone

Posted by GitBox <gi...@apache.org>.
viirya merged PR #2608:
URL: https://github.com/apache/arrow-rs/pull/2608


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


[GitHub] [arrow-rs] sunchao commented on a diff in pull request #2608: Cast timestamp array to string array with timezone

Posted by GitBox <gi...@apache.org>.
sunchao commented on code in PR #2608:
URL: https://github.com/apache/arrow-rs/pull/2608#discussion_r959969219


##########
arrow/src/compute/kernels/temporal.rs:
##########
@@ -28,33 +28,33 @@ use chrono::format::{parse, Parsed};
 use chrono::FixedOffset;
 
 macro_rules! extract_component_from_array {
-    ($array:ident, $builder:ident, $extract_fn:ident, $using:ident) => {
+    ($array:ident, $builder:ident, $extract_fn:ident, $using:ident, $convert:expr) => {

Review Comment:
   why we need the `$convert`?



##########
arrow/src/compute/kernels/mod.rs:
##########
@@ -35,5 +35,6 @@ pub mod sort;
 pub mod substring;
 pub mod take;
 pub mod temporal;
+// pub(crate) use temporal::extract_component_from_array;

Review Comment:
   what is this for?



##########
arrow/src/compute/kernels/cast.rs:
##########
@@ -1482,25 +1487,35 @@ where
 }
 
 /// Cast timestamp types to Utf8/LargeUtf8
-fn cast_timestamp_to_string<T, OffsetSize>(array: &ArrayRef) -> Result<ArrayRef>
+fn cast_timestamp_to_string<T, OffsetSize>(
+    array: &ArrayRef,
+    tz: &Option<String>,
+) -> Result<ArrayRef>
 where
     T: ArrowTemporalType + ArrowNumericType,
     i64: From<<T as ArrowPrimitiveType>::Native>,
     OffsetSize: OffsetSizeTrait,
 {
     let array = array.as_any().downcast_ref::<PrimitiveArray<T>>().unwrap();
 
-    Ok(Arc::new(
-        (0..array.len())
-            .map(|ix| {
-                if array.is_null(ix) {
-                    None
-                } else {
-                    array.value_as_datetime(ix).map(|v| v.to_string())
-                }
-            })
-            .collect::<GenericStringArray<OffsetSize>>(),
-    ))
+    let mut builder = GenericStringBuilder::<OffsetSize>::new();
+
+    if let Some(tz) = tz {
+        let mut scratch = Parsed::new();
+        extract_component_from_array!(

Review Comment:
   it's not too obvious to see what this is doing, maybe add some comments?



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


[GitHub] [arrow-rs] viirya commented on pull request #2608: Cast timestamp array to string array with timezone

Posted by GitBox <gi...@apache.org>.
viirya commented on PR #2608:
URL: https://github.com/apache/arrow-rs/pull/2608#issuecomment-1233336578

   cc @sunchao 


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