Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dyn comparison of interval arrays (#1106) #1107

Merged
merged 5 commits into from
Jan 6, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 91 additions & 3 deletions arrow/src/compute/kernels/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ use crate::compute::binary_boolean_kernel;
use crate::compute::util::combine_option_bitmap;
use crate::datatypes::{
ArrowNumericType, DataType, Date32Type, Date64Type, Float32Type, Float64Type,
Int16Type, Int32Type, Int64Type, Int8Type, TimeUnit, TimestampMicrosecondType,
TimestampMillisecondType, TimestampNanosecondType, TimestampSecondType, UInt16Type,
UInt32Type, UInt64Type, UInt8Type,
Int16Type, Int32Type, Int64Type, Int8Type, IntervalDayTimeType,
IntervalMonthDayNanoType, IntervalUnit, IntervalYearMonthType, TimeUnit,
TimestampMicrosecondType, TimestampMillisecondType, TimestampNanosecondType,
TimestampSecondType, UInt16Type, UInt32Type, UInt64Type, UInt8Type,
};
use crate::error::{ArrowError, Result};
use crate::util::bit_util;
Expand Down Expand Up @@ -1192,6 +1193,42 @@ macro_rules! typed_compares {
(DataType::Date64, DataType::Date64) => {
typed_cmp!($LEFT, $RIGHT, Date64Array, $OP_PRIM, Date64Type)
}
(
DataType::Interval(IntervalUnit::YearMonth),
DataType::Interval(IntervalUnit::YearMonth),
) => {
typed_cmp!(
$LEFT,
$RIGHT,
IntervalYearMonthArray,
$OP_PRIM,
IntervalYearMonthType
)
}
(
DataType::Interval(IntervalUnit::DayTime),
DataType::Interval(IntervalUnit::DayTime),
) => {
typed_cmp!(
$LEFT,
$RIGHT,
IntervalDayTimeArray,
$OP_PRIM,
IntervalDayTimeType
)
}
(
DataType::Interval(IntervalUnit::MonthDayNano),
DataType::Interval(IntervalUnit::MonthDayNano),
) => {
typed_cmp!(
$LEFT,
$RIGHT,
IntervalMonthDayNanoArray,
$OP_PRIM,
IntervalMonthDayNanoType
)
}
(t1, t2) if t1 == t2 => Err(ArrowError::NotYetImplemented(format!(
"Comparing arrays of type {} is not yet implemented",
t1
Expand Down Expand Up @@ -2128,6 +2165,57 @@ mod tests {
);
}

#[test]
fn test_interval_array() {
let a = IntervalDayTimeArray::from(
vec![Some(0), Some(6), Some(834), None, Some(3), None],
);
let b = IntervalDayTimeArray::from(
vec![Some(70), Some(6), Some(833), Some(6), Some(3), None],
);
let res = eq(&a, &b).unwrap();
let res_dyn = eq_dyn(&a, &b).unwrap();
assert_eq!(res, res_dyn);
assert_eq!(
&res_dyn,
&BooleanArray::from(
vec![Some(false), Some(true), Some(false), None, Some(true), None]
)
);

let a = IntervalMonthDayNanoArray::from(
vec![Some(0), Some(6), Some(834), None, Some(3), None],
);
let b = IntervalMonthDayNanoArray::from(
vec![Some(86), Some(5), Some(8), Some(6), Some(3), None],
);
let res = lt(&a, &b).unwrap();
let res_dyn = lt_dyn(&a, &b).unwrap();
assert_eq!(res, res_dyn);
assert_eq!(
&res_dyn,
&BooleanArray::from(
vec![Some(true), Some(false), Some(false), None, Some(false), None]
)
);

let a = IntervalYearMonthArray::from(
vec![Some(0), Some(623), Some(834), None, Some(3), None],
);
let b = IntervalYearMonthArray::from(
vec![Some(86), Some(5), Some(834), Some(6), Some(86), None],
);
let res = gt_eq(&a, &b).unwrap();
let res_dyn = gt_eq_dyn(&a, &b).unwrap();
assert_eq!(res, res_dyn);
assert_eq!(
&res_dyn,
&BooleanArray::from(
vec![Some(false), Some(true), Some(true), None, Some(false), None]
)
);
}

// Expected behaviour:
// contains("ab", ["ab", "cd", null]) = true
// contains("ef", ["ab", "cd", null]) = false
Expand Down