alamb commented on code in PR #2031: URL: https://github.com/apache/arrow-rs/pull/2031#discussion_r919926663
########## arrow/src/compute/kernels/arithmetic.rs: ########## @@ -1068,6 +1122,92 @@ mod tests { assert_eq!(17, c.value(4)); } + #[test] + fn test_date32_month_add() { + let a = Date32Array::from(vec![Date32Type::from_naive_date( + NaiveDate::from_ymd(2000, 1, 1), + )]); + let b = IntervalYearMonthArray::from(vec![IntervalYearMonthType::new(1, 2)]); + let c = add_dyn(&a, &b).unwrap(); + let c = c.as_any().downcast_ref::<Date32Array>().unwrap(); + assert_eq!( + c.value(0), + Date32Type::from_naive_date(NaiveDate::from_ymd(2001, 3, 1)) + ); + } + + #[test] + fn test_date32_day_time_add() { + let a = Date32Array::from(vec![Date32Type::from_naive_date( + NaiveDate::from_ymd(2000, 1, 1), + )]); + let b = IntervalDayTimeArray::from(vec![IntervalDayTimeType::new(1, 2)]); + let c = add_dyn(&a, &b).unwrap(); + let c = c.as_any().downcast_ref::<Date32Array>().unwrap(); + assert_eq!( + c.value(0), + Date32Type::from_naive_date(NaiveDate::from_ymd(2000, 1, 2)) + ); + } + + #[test] + fn test_date32_month_day_nano_add() { + let a = Date32Array::from(vec![Date32Type::from_naive_date( + NaiveDate::from_ymd(2000, 1, 1), + )]); + let b = + IntervalMonthDayNanoArray::from(vec![IntervalMonthDayNanoType::new(1, 2, 3)]); + let c = add_dyn(&a, &b).unwrap(); + let c = c.as_any().downcast_ref::<Date32Array>().unwrap(); + assert_eq!( + c.value(0), + Date32Type::from_naive_date(NaiveDate::from_ymd(2000, 2, 3)) + ); + } + + #[test] + fn test_date64_month_add() { + let a = Date64Array::from(vec![Date64Type::from_naive_date( + NaiveDate::from_ymd(2000, 1, 1), + )]); + let b = IntervalYearMonthArray::from(vec![IntervalYearMonthType::new(1, 2)]); + let c = add_dyn(&a, &b).unwrap(); Review Comment: it is so great to see `add_dyn` used like this ❤️ ########## arrow/src/datatypes/types.rs: ########## @@ -191,3 +194,166 @@ impl ArrowTimestampType for TimestampNanosecondType { TimeUnit::Nanosecond } } + +impl IntervalYearMonthType { + /// Creates a IntervalYearMonthType Review Comment: I think the functionality for manipulating values on to this `impl` makes sense Perhaps @viirya was referring to the rust convention that `Type::new()` returns an instance of `Type` -- perhaps if we renamed this method `make_value` or something like that it would be less surprising for other rust developers. We could do it as a follow on PR as well (before releasing arrow 19.x) too -- 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-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org