Skip to content

Commit

Permalink
Fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
viirya committed Oct 8, 2022
1 parent 7bc3318 commit ac28f11
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 102 deletions.
28 changes: 13 additions & 15 deletions arrow/src/compute/kernels/cast.rs
Expand Up @@ -1745,7 +1745,7 @@ fn extract_component_from_datatime_array<
>(
iter: ArrayIter<A>,
mut builder: GenericStringBuilder<OffsetSize>,
tz: &String,
tz: &str,
mut parsed: Parsed,
op: F,
) -> Result<ArrayRef>
Expand All @@ -1760,7 +1760,7 @@ where
"Expected format [+-]XX:XX".to_string()
)
} else {
let tz_parse_result = parse(&mut parsed, &tz, StrftimeItems::new("%z"));
let tz_parse_result = parse(&mut parsed, tz, StrftimeItems::new("%z"));
let fixed_offset_from_parsed = match tz_parse_result {
Ok(_) => match parsed.to_fixed_offset() {
Ok(fo) => Some(fo),
Expand All @@ -1769,14 +1769,14 @@ where
_ => None,
};

for value in iter.into_iter() {
for value in iter {
if let Some(value) = value {
match as_datetime::<T>(<i64 as From<_>>::from(value)) {
Some(utc) => {
let fixed_offset = match fixed_offset_from_parsed {
Some(fo) => fo,
None => {
match using_chrono_tz_and_utc_naive_date_time(&tz, utc) {
match using_chrono_tz_and_utc_naive_date_time(tz, utc) {
Some(fo) => fo,
err => return_compute_error_with!(
"Unable to parse timezone",
Expand Down Expand Up @@ -1820,23 +1820,21 @@ where
// After applying timezone offset on the datatime, calling `to_string` to get
// the strings.
let iter = ArrayIter::new(array);
return Ok(
extract_component_from_datatime_array::<_, OffsetSize, T, _>(
iter,
builder,
tz,
scratch,
|t| t.to_string(),
)?,
);
extract_component_from_datatime_array::<_, OffsetSize, T, _>(
iter,
builder,
tz,
scratch,
|t| t.to_string(),
)
} else {
// No timezone available. Calling `to_string` on the datatime value simply.
let iter = ArrayIter::new(array);
return Ok(as_time_with_string_op::<_, OffsetSize, T, _>(
Ok(as_time_with_string_op::<_, OffsetSize, T, _>(
iter,
builder,
|t| t.to_string(),
));
))
}
}

Expand Down
138 changes: 51 additions & 87 deletions arrow/src/compute/kernels/temporal.rs
Expand Up @@ -81,7 +81,7 @@ fn extract_component_from_datatime_array<
>(
iter: ArrayIter<A>,
mut builder: PrimitiveBuilder<Int32Type>,
tz: &String,
tz: &str,
mut parsed: Parsed,
op: F,
) -> Result<Int32Array>
Expand All @@ -95,7 +95,7 @@ where
"Expected format [+-]XX:XX".to_string()
)
} else {
let tz_parse_result = parse(&mut parsed, &tz, StrftimeItems::new("%z"));
let tz_parse_result = parse(&mut parsed, tz, StrftimeItems::new("%z"));
let fixed_offset_from_parsed = match tz_parse_result {
Ok(_) => match parsed.to_fixed_offset() {
Ok(fo) => Some(fo),
Expand All @@ -104,14 +104,14 @@ where
_ => None,
};

for value in iter.into_iter() {
for value in iter {
if let Some(value) = value {
match as_datetime::<T>(i64::from(value)) {
Some(utc) => {
let fixed_offset = match fixed_offset_from_parsed {
Some(fo) => fo,
None => {
match using_chrono_tz_and_utc_naive_date_time(&tz, utc) {
match using_chrono_tz_and_utc_naive_date_time(tz, utc) {
Some(fo) => fo,
err => return_compute_error_with!(
"Unable to parse timezone",
Expand Down Expand Up @@ -237,22 +237,18 @@ where
match dt {
DataType::Time32(_) | DataType::Time64(_) => {
let iter = ArrayIter::new(array);
return Ok(as_time_with_op::<A, T, _>(iter, b, |t| t.hour() as i32));
Ok(as_time_with_op::<A, T, _>(iter, b, |t| t.hour() as i32))
}
DataType::Date32 | DataType::Date64 | DataType::Timestamp(_, None) => {
let iter = ArrayIter::new(array);
return Ok(as_datetime_with_op::<A, T, _>(iter, b, |t| t.hour() as i32));
Ok(as_datetime_with_op::<A, T, _>(iter, b, |t| t.hour() as i32))
}
DataType::Timestamp(_, Some(tz)) => {
let scratch = Parsed::new();
let iter = ArrayIter::new(array);
return Ok(extract_component_from_datatime_array::<A, T, _>(
iter,
b,
tz,
scratch,
|t| t.hour() as i32,
)?);
extract_component_from_datatime_array::<A, T, _>(iter, b, tz, scratch, |t| {
t.hour() as i32
})
}
_ => return_compute_error_with!("hour does not support", array.data_type()),
}
Expand Down Expand Up @@ -294,7 +290,7 @@ where
DataType::Date32 | DataType::Date64 | DataType::Timestamp(_, _) => {
let b = Int32Builder::with_capacity(array.len());
let iter = ArrayIter::new(array);
return Ok(as_datetime_with_op::<A, T, _>(iter, b, |t| t.year()));
Ok(as_datetime_with_op::<A, T, _>(iter, b, |t| t.year()))
}
_t => return_compute_error_with!("year does not support", array.data_type()),
}
Expand Down Expand Up @@ -340,20 +336,16 @@ where
match dt {
DataType::Date32 | DataType::Date64 | DataType::Timestamp(_, None) => {
let iter = ArrayIter::new(array);
return Ok(as_datetime_with_op::<A, T, _>(iter, b, |t| {
Ok(as_datetime_with_op::<A, T, _>(iter, b, |t| {
t.quarter() as i32
}));
}))
}
DataType::Timestamp(_, Some(tz)) => {
let scratch = Parsed::new();
let iter = ArrayIter::new(array);
return Ok(extract_component_from_datatime_array::<A, T, _>(
iter,
b,
tz,
scratch,
|t| t.quarter() as i32,
)?);
extract_component_from_datatime_array::<A, T, _>(iter, b, tz, scratch, |t| {
t.quarter() as i32
})
}
_ => return_compute_error_with!("quarter does not support", array.data_type()),
}
Expand Down Expand Up @@ -398,20 +390,16 @@ where
match dt {
DataType::Date32 | DataType::Date64 | DataType::Timestamp(_, None) => {
let iter = ArrayIter::new(array);
return Ok(as_datetime_with_op::<A, T, _>(iter, b, |t| {
Ok(as_datetime_with_op::<A, T, _>(iter, b, |t| {
t.month() as i32
}));
}))
}
DataType::Timestamp(_, Some(tz)) => {
let scratch = Parsed::new();
let iter = ArrayIter::new(array);
return Ok(extract_component_from_datatime_array::<A, T, _>(
iter,
b,
tz,
scratch,
|t| t.month() as i32,
)?);
extract_component_from_datatime_array::<A, T, _>(iter, b, tz, scratch, |t| {
t.month() as i32
})
}
_ => return_compute_error_with!("month does not support", array.data_type()),
}
Expand Down Expand Up @@ -470,20 +458,16 @@ where
match dt {
DataType::Date32 | DataType::Date64 | DataType::Timestamp(_, None) => {
let iter = ArrayIter::new(array);
return Ok(as_datetime_with_op::<A, T, _>(iter, b, |t| {
Ok(as_datetime_with_op::<A, T, _>(iter, b, |t| {
t.num_days_from_monday()
}));
}))
}
DataType::Timestamp(_, Some(tz)) => {
let scratch = Parsed::new();
let iter = ArrayIter::new(array);
return Ok(extract_component_from_datatime_array::<A, T, _>(
iter,
b,
tz,
scratch,
|t| t.num_days_from_monday(),
)?);
extract_component_from_datatime_array::<A, T, _>(iter, b, tz, scratch, |t| {
t.num_days_from_monday()
})
}
_ => return_compute_error_with!("weekday does not support", array.data_type()),
}
Expand Down Expand Up @@ -542,20 +526,16 @@ where
match dt {
DataType::Date32 | DataType::Date64 | DataType::Timestamp(_, None) => {
let iter = ArrayIter::new(array);
return Ok(as_datetime_with_op::<A, T, _>(iter, b, |t| {
Ok(as_datetime_with_op::<A, T, _>(iter, b, |t| {
t.num_days_from_sunday()
}));
}))
}
DataType::Timestamp(_, Some(tz)) => {
let scratch = Parsed::new();
let iter = ArrayIter::new(array);
return Ok(extract_component_from_datatime_array::<A, T, _>(
iter,
b,
tz,
scratch,
|t| t.num_days_from_sunday(),
)?);
extract_component_from_datatime_array::<A, T, _>(iter, b, tz, scratch, |t| {
t.num_days_from_sunday()
})
}
_ => return_compute_error_with!(
"num_days_from_sunday does not support",
Expand Down Expand Up @@ -600,18 +580,14 @@ where
match dt {
DataType::Date32 | DataType::Date64 | DataType::Timestamp(_, None) => {
let iter = ArrayIter::new(array);
return Ok(as_datetime_with_op::<A, T, _>(iter, b, |t| t.day() as i32));
Ok(as_datetime_with_op::<A, T, _>(iter, b, |t| t.day() as i32))
}
DataType::Timestamp(_, Some(ref tz)) => {
let scratch = Parsed::new();
let iter = ArrayIter::new(array);
return Ok(extract_component_from_datatime_array::<A, T, _>(
iter,
b,
tz,
scratch,
|t| t.day() as i32,
)?);
extract_component_from_datatime_array::<A, T, _>(iter, b, tz, scratch, |t| {
t.day() as i32
})
}
_ => return_compute_error_with!("day does not support", array.data_type()),
}
Expand Down Expand Up @@ -657,20 +633,16 @@ where
match dt {
DataType::Date32 | DataType::Date64 | DataType::Timestamp(_, None) => {
let iter = ArrayIter::new(array);
return Ok(as_datetime_with_op::<A, T, _>(iter, b, |t| {
Ok(as_datetime_with_op::<A, T, _>(iter, b, |t| {
t.ordinal() as i32
}));
}))
}
DataType::Timestamp(_, Some(ref tz)) => {
let scratch = Parsed::new();
let iter = ArrayIter::new(array);
return Ok(extract_component_from_datatime_array::<A, T, _>(
iter,
b,
tz,
scratch,
|t| t.ordinal() as i32,
)?);
extract_component_from_datatime_array::<A, T, _>(iter, b, tz, scratch, |t| {
t.ordinal() as i32
})
}
_ => return_compute_error_with!("doy does not support", array.data_type()),
}
Expand Down Expand Up @@ -714,20 +686,16 @@ where
match dt {
DataType::Date64 | DataType::Timestamp(_, None) => {
let iter = ArrayIter::new(array);
return Ok(as_datetime_with_op::<A, T, _>(iter, b, |t| {
Ok(as_datetime_with_op::<A, T, _>(iter, b, |t| {
t.minute() as i32
}));
}))
}
DataType::Timestamp(_, Some(tz)) => {
let scratch = Parsed::new();
let iter = ArrayIter::new(array);
return Ok(extract_component_from_datatime_array::<A, T, _>(
iter,
b,
tz,
scratch,
|t| t.minute() as i32,
)?);
extract_component_from_datatime_array::<A, T, _>(iter, b, tz, scratch, |t| {
t.minute() as i32
})
}
_ => return_compute_error_with!("minute does not support", array.data_type()),
}
Expand Down Expand Up @@ -769,9 +737,9 @@ where
DataType::Date32 | DataType::Date64 | DataType::Timestamp(_, None) => {
let b = Int32Builder::with_capacity(array.len());
let iter = ArrayIter::new(array);
return Ok(as_datetime_with_op::<A, T, _>(iter, b, |t| {
Ok(as_datetime_with_op::<A, T, _>(iter, b, |t| {
t.iso_week().week() as i32
}));
}))
}
_ => return_compute_error_with!("week does not support", array.data_type()),
}
Expand Down Expand Up @@ -815,20 +783,16 @@ where
match dt {
DataType::Date64 | DataType::Timestamp(_, None) => {
let iter = ArrayIter::new(array);
return Ok(as_datetime_with_op::<A, T, _>(iter, b, |t| {
Ok(as_datetime_with_op::<A, T, _>(iter, b, |t| {
t.second() as i32
}));
}))
}
DataType::Timestamp(_, Some(tz)) => {
let scratch = Parsed::new();
let iter = ArrayIter::new(array);
return Ok(extract_component_from_datatime_array::<A, T, _>(
iter,
b,
tz,
scratch,
|t| t.second() as i32,
)?);
extract_component_from_datatime_array::<A, T, _>(iter, b, tz, scratch, |t| {
t.second() as i32
})
}
_ => return_compute_error_with!("second does not support", array.data_type()),
}
Expand Down

0 comments on commit ac28f11

Please sign in to comment.