berkaysynnada opened a new pull request, #5180:
URL: https://github.com/apache/arrow-rs/pull/5180
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases. You can
link an issue to this PR using the GitHub syntax. For example `Closes #123`
indicates that this PR will close issue #123.
-->
Closes #.
# Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in
the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your
changes and offer better suggestions for fixes.
-->
When intervals are compared, `IntervalDayTimeArray` and
`IntervalMonthDayNanoArray` exhibit unexpected behavior. This occurs because
they are treated as signed integers, but they require special handling since
they consist of multiple contiguous time unit blocks.
```
#[test]
fn test_interval_cmp() {
let a =
IntervalDayTimeArray::from(vec![Some(IntervalDayTimeType::make_value(0, -5))]);
let b =
IntervalDayTimeArray::from(vec![Some(IntervalDayTimeType::make_value(0, 5))]);
let res = gt(&a, &b).unwrap();
assert_eq!(&res, &BooleanArray::from(vec![ Some(false)]));
}
...
...
...
assertion `left == right` failed
left: BooleanArray
[
true,
]
right: BooleanArray
[
false,
]
```
The first unexpected behavior is observed when the LSD parts of these
intervals are negative numbers and the MSD's are 0; under these conditions,
intervals with negative values are evaluated as if they are greater than those
with positive values.
```
#[test]
fn test_interval_cmp() {
let a = IntervalMonthDayNanoArray::from(
vec![Some(IntervalMonthDayNanoType::make_value(0, -10, 0))],
);
let b = IntervalMonthDayNanoArray::from(
vec![Some(IntervalMonthDayNanoType::make_value(0, 20,0))],
);
let res = gt(&a, &b).unwrap();
assert_eq!(&res, &BooleanArray::from(vec![ Some(false)]));
}
```
This test also fails in a similar manner.
The second problem arises when comparing relative intervals, such as 1 month
and 30 days. In such cases, we can not arrive at an absolute result (e.g. days
in a month can change). Therefore, to stay on the safe side, we adopt the
following semantics: A comparison returns true if it holds certainly.
Otherwise, it returns false. Going back to our example, we return false for
both 1 month < 30 days and 1 month > 30 days. It is impossible to impose a
total order on intervals, but we can impose a consistent partial order with
this logic.
# What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is
sometimes worth providing a summary of the individual changes in this PR.
-->
`IntervalDayTimeArray` and `IntervalMonthDayNanoArray` are separately
handled before passing to `apply()` in `compare_op()`. They will be represented
with milliseconds and nanoseconds, respectively, as the maximum or minimum
value that the interval may correspond to.
As we need an exact representation of `IntervalMonthDayNano` in nanoseconds
to prevent overflow cases, a variant for a 128-bit signed integer in DataType
is added. Necessary extensions are accordingly implemented.
# Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->
<!---
If there are any breaking changes to public APIs, please add the `breaking
change` label.
-->
--
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]