MCPcopy Create free account
hub / github.com/apache/arrow-rs / test_timestamp_impl

Function test_timestamp_impl

arrow-arith/src/numeric.rs:1293–1391  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1291 }
1292
1293 fn test_timestamp_impl<T: TimestampOp>() {
1294 let a = PrimitiveArray::<T>::new(vec![2000000, 434030324, 53943340].into(), None);
1295 let b = PrimitiveArray::<T>::new(vec![329593, 59349, 694994].into(), None);
1296
1297 let result = sub(&a, &b).unwrap();
1298 assert_eq!(
1299 result.as_primitive::<T::Duration>().values(),
1300 &[1670407, 433970975, 53248346]
1301 );
1302
1303 let r2 = add(&b, &result.as_ref()).unwrap();
1304 assert_eq!(r2.as_ref(), &a);
1305
1306 let r3 = add(&result.as_ref(), &b).unwrap();
1307 assert_eq!(r3.as_ref(), &a);
1308
1309 let format_array = |x: &dyn Array| -> Vec<String> {
1310 x.as_primitive::<T>()
1311 .values()
1312 .into_iter()
1313 .map(|x| as_datetime::<T>(*x).unwrap().to_string())
1314 .collect()
1315 };
1316
1317 let values = vec![
1318 "1970-01-01T00:00:00Z",
1319 "2010-04-01T04:00:20Z",
1320 "1960-01-30T04:23:20Z",
1321 ]
1322 .into_iter()
1323 .map(|x| {
1324 T::from_naive_datetime(DateTime::parse_from_rfc3339(x).unwrap().naive_utc(), None)
1325 .unwrap()
1326 })
1327 .collect();
1328
1329 let a = PrimitiveArray::<T>::new(values, None);
1330 let b = IntervalYearMonthArray::from(vec![
1331 IntervalYearMonthType::make_value(5, 34),
1332 IntervalYearMonthType::make_value(-2, 4),
1333 IntervalYearMonthType::make_value(7, -4),
1334 ]);
1335 let r4 = add(&a, &b).unwrap();
1336 assert_eq!(
1337 &format_array(r4.as_ref()),
1338 &[
1339 "1977-11-01 00:00:00".to_string(),
1340 "2008-08-01 04:00:20".to_string(),
1341 "1966-09-30 04:23:20".to_string()
1342 ]
1343 );
1344
1345 let r5 = sub(&r4, &b).unwrap();
1346 assert_eq!(r5.as_ref(), &a);
1347
1348 let b = IntervalDayTimeArray::from(vec![
1349 IntervalDayTimeType::make_value(5, 454000),
1350 IntervalDayTimeType::make_value(-34, 0),

Callers

nothing calls this directly

Calls 6

subFunction · 0.85
addFunction · 0.85
collectMethod · 0.80
as_refMethod · 0.45
into_iterMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected