viirya commented on code in PR #2623:
URL: https://github.com/apache/arrow-rs/pull/2623#discussion_r960998136
##########
arrow/src/compute/kernels/temporal.rs:
##########
@@ -28,40 +29,40 @@ use chrono::format::{parse, Parsed};
use chrono::FixedOffset;
macro_rules! extract_component_from_array {
- ($array:ident, $builder:ident, $extract_fn:ident, $using:ident,
$convert:expr) => {
- for i in 0..$array.len() {
- if $array.is_null(i) {
- $builder.append_null();
- } else {
- match $array.$using(i) {
+ ($iter:ident, $builder:ident, $extract_fn:ident, $using:expr,
$convert:expr) => {
+ $iter.into_iter().for_each(|value| {
+ if let Some(value) = value {
+ match $using(value) {
Some(dt) =>
$builder.append_value($convert(dt.$extract_fn())),
None => $builder.append_null(),
}
+ } else {
+ $builder.append_null();
}
- }
+ })
Review Comment:
This change basically rewrites the macro using ArrayAccessor API. Otherwise
the logic is the same.
Previously the macro can call `value_as_datetime`,
`value_as_datetime_with_tz` APIs on temporal array, but now we need to call
`as_datetime` on the value instead.
##########
arrow/src/compute/kernels/temporal.rs:
##########
@@ -28,40 +29,40 @@ use chrono::format::{parse, Parsed};
use chrono::FixedOffset;
macro_rules! extract_component_from_array {
- ($array:ident, $builder:ident, $extract_fn:ident, $using:ident,
$convert:expr) => {
- for i in 0..$array.len() {
- if $array.is_null(i) {
- $builder.append_null();
- } else {
- match $array.$using(i) {
+ ($iter:ident, $builder:ident, $extract_fn:ident, $using:expr,
$convert:expr) => {
+ $iter.into_iter().for_each(|value| {
+ if let Some(value) = value {
+ match $using(value) {
Some(dt) =>
$builder.append_value($convert(dt.$extract_fn())),
None => $builder.append_null(),
}
+ } else {
+ $builder.append_null();
}
- }
+ })
Review Comment:
This change basically rewrites the macro using ArrayAccessor API. Otherwise
the logic is the same.
Previously the macro can call `value_as_datetime`or
`value_as_datetime_with_tz` APIs on temporal array, but now we need to call
`as_datetime` on the value instead.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]