Skip to content

Comments

Add Datum Arithmetic tests, Fix Interval Substraction (#4480)#4493

Merged
tustvold merged 4 commits intoapache:masterfrom
tustvold:arithmetic-tests
Jul 10, 2023
Merged

Add Datum Arithmetic tests, Fix Interval Substraction (#4480)#4493
tustvold merged 4 commits intoapache:masterfrom
tustvold:arithmetic-tests

Conversation

@tustvold
Copy link
Contributor

@tustvold tustvold commented Jul 8, 2023

Which issue does this PR close?

Closes #4480
Closes #4489
Closes #1065

Rationale for this change

What changes are included in this PR?

Are there any user-facing changes?

@github-actions github-actions bot added the arrow Changes to the arrow crate label Jul 8, 2023
assert_eq!(
c.value(0),
Date32Type::from_naive_date(NaiveDate::from_ymd_opt(2023, 3, 27).unwrap())
Date32Type::from_naive_date(NaiveDate::from_ymd_opt(2023, 3, 28).unwrap())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous logic was incorrect but happened to give a potentially plausible result. I'm not sure what the correct rounding behaviour is here though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Date32: https://docs.rs/arrow/latest/arrow/datatypes/enum.IntervalUnit.html

86500 is milliseconds so 86.5 seconds before 2023-03-29

Thus 2023-03-28 seems much more correct to me

@tustvold tustvold changed the title Add Datum Arithmetic tests (#4480) Add Datum Arithmetic tests, Fix Interval Substraction (#4480) Jul 8, 2023
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @tustvold -- this looks really nice to me

assert_eq!(
c.value(0),
Date32Type::from_naive_date(NaiveDate::from_ymd_opt(2023, 3, 27).unwrap())
Date32Type::from_naive_date(NaiveDate::from_ymd_opt(2023, 3, 28).unwrap())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Date32: https://docs.rs/arrow/latest/arrow/datatypes/enum.IntervalUnit.html

86500 is milliseconds so 86.5 seconds before 2023-03-29

Thus 2023-03-28 seems much more correct to me

}

impl std::fmt::Display for Op {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯


let l_mul = T::Native::usize_as(10).pow_wrapping((result_scale - s1) as _);
let r_mul = T::Native::usize_as(10).pow_wrapping((result_scale - s2) as _);
let l_mul = T::Native::usize_as(10).pow_checked((result_scale - s1) as _)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was a little confused at first about why both AddWrapping and Add using the same function. Then
I realized this is for computing the scale factor

Given MAX_PRECISION is a constant, what is the reason to change this to pow_checked? Maybe it doesn't matter performance wise, I was just curious

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can overflow on negative scales

let a = UInt8Array::from(vec![56, 5, 3]);
let b = UInt8Array::from(vec![200, 2, 5]);
let err = add(&a, &b).unwrap_err().to_string();
assert_eq!(err, "Compute error: Overflow happened on: 56 + 200");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👨‍🍳 👌 very nice message

let a = Int16Array::from(vec![21]);
let b = Int16Array::from(vec![0]);
let err = div(&a, &b).unwrap_err().to_string();
assert_eq!(err, "Divide by zero error");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see a test for integer remainder %

.with_precision_and_scale(37, 37)
.unwrap();
let err = mul(&a, &b).unwrap_err().to_string();
assert_eq!(err, "Invalid argument error: Output scale of Decimal128(3, 3) * Decimal128(37, 37) would exceed max scale of 38");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

let a = PrimitiveArray::<T>::new(values, None);
let b = IntervalYearMonthArray::from(vec![
IntervalYearMonthType::make_value(5, 34),
IntervalYearMonthType::make_value(-2, 4),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add a test for overflow (like subtracting two months from 1970-01-01T00:00:00Z?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently the overflow behaviour is a little broken, #4456 tracks fixing this.

assert_eq!(
err,
"Compute error: Overflow happened on: 9223372036854775807 + 1"
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it worthing adding a test here showing that * and / are not supported for durations?

})?;
let res = res
.checked_add_signed(Duration::microseconds(ms as i64))
.checked_sub_signed(Duration::milliseconds(ms as i64))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bug fix -- that IntervalDayTime stores data in milliseconds not microseconds 👍

@tustvold tustvold merged commit 6bbf2f0 into apache:master Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect Interval Subtraction Port Tests from Deprecated Arithmetic Kernels Incorrect Numeric operations on MONTH_DAY_NANO interval type

2 participants