mbutrovich commented on code in PR #12422:
URL: https://github.com/apache/arrow-rs/pull/12422#discussion_r4671266239
##########
arrow-cast/benches/cast_timestamp.rs:
##########
@@ -51,11 +71,57 @@ fn benchmark<T: ArrowTimestampType>(c: &mut Criterion,
unit: &str, units_per_sec
group.finish();
}
+/// Returns the names and units other than `unit`
+fn other_units(unit: TimeUnit) -> impl Iterator<Item = (&'static str,
TimeUnit)> {
+ [
+ ("s", TimeUnit::Second),
+ ("ms", TimeUnit::Millisecond),
+ ("us", TimeUnit::Microsecond),
+ ("ns", TimeUnit::Nanosecond),
+ ]
+ .into_iter()
+ .filter(move |(_, u)| *u != unit)
+}
+
+fn duration_benchmark<T: ArrowPrimitiveType<Native = i64>>(
+ c: &mut Criterion,
+ unit: &str,
+ from: TimeUnit,
+ units_per_second: i64,
+) {
+ // Durations of up to roughly 63 years either way
+ let mut rng = StdRng::seed_from_u64(42);
Review Comment:
Done, as `arrays::<T>(units_per_second)`, which both functions call.
##########
arrow-cast/tests/cast/date_time.rs:
##########
@@ -2723,3 +2723,66 @@ fn test_cast_temporal_scaling_boundaries() {
check::<Date64Type, TimestampMicrosecondType>(MICROSECONDS / MILLISECONDS);
check::<Date64Type, TimestampNanosecondType>(NANOSECONDS / MILLISECONDS);
}
+
+#[test]
+fn test_cast_timestamp_and_duration_to_coarser_unit() {
+ // Truncates toward zero, as `/` does, and keeps nulls
+ let edges = [
+ i64::MIN,
+ i64::MIN + 1,
+ -1_000_000_001,
+ -1_000_000_000,
+ -999_999_999,
+ -1001,
+ -1000,
+ -999,
+ -1,
+ 0,
+ 1,
+ 999,
+ 1000,
+ 1001,
+ 999_999_999,
+ 1_000_000_000,
+ 1_000_000_001,
+ i64::MAX - 1,
+ i64::MAX,
+ ];
+ let values: Int64Array = edges
+ .into_iter()
+ .map(Some)
+ .chain([None])
+ .cycle()
+ .take(70)
+ .collect();
+ let units = [
+ TimeUnit::Second,
+ TimeUnit::Millisecond,
+ TimeUnit::Microsecond,
+ TimeUnit::Nanosecond,
+ ];
+ let tz = Some("+05:45".into());
+ for array in [values.clone(), values.slice(3, 60)] {
+ for (i, from) in units.into_iter().enumerate() {
+ for (j, to) in units.into_iter().enumerate().take(i) {
Review Comment:
Done, all three.
--
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]