Skip to content

Commit 08d730d

Browse files
authored
fix: Handle comparing VarBinArray to other non VarBin Utf8/BinaryDType arrays (#3423)
Signed-off-by: Robert Kruszewski <[email protected]>
1 parent c9c966a commit 08d730d

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

vortex-array/src/arrays/varbin/compute/compare.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use itertools::Itertools;
55
use vortex_dtype::{DType, NativePType, match_each_native_ptype};
66
use vortex_error::{VortexExpect as _, VortexResult, vortex_bail, vortex_err};
77

8-
use crate::arrays::{BoolArray, PrimitiveArray, VarBinArray, VarBinVTable, VarBinViewVTable};
8+
use crate::arrays::{BoolArray, PrimitiveArray, VarBinArray, VarBinVTable};
99
use crate::arrow::{Datum, from_arrow_array_with_len};
1010
use crate::compute::{
1111
CompareKernel, CompareKernelAdapter, Operator, compare, compare_lengths_to_empty,
@@ -87,7 +87,8 @@ impl CompareKernel for VarBinVTable {
8787
.map_err(|err| vortex_err!("Failed to compare VarBin array: {}", err))?;
8888

8989
Ok(Some(from_arrow_array_with_len(&array, len, nullable)?))
90-
} else if rhs.is::<VarBinViewVTable>() {
90+
} else if !rhs.is::<VarBinVTable>() {
91+
// NOTE: If the rhs is not a VarBin array it will be canonicalized to a VarBinView
9192
// Arrow doesn't support comparing VarBin to VarBinView arrays, so we convert ourselves
9293
// to VarBinView and re-invoke.
9394
return Ok(Some(compare(lhs.to_varbinview()?.as_ref(), rhs, operator)?));
@@ -119,7 +120,7 @@ mod test {
119120
use vortex_scalar::Scalar;
120121

121122
use crate::ToCanonical;
122-
use crate::arrays::{ConstantArray, VarBinArray};
123+
use crate::arrays::{ConstantArray, VarBinArray, VarBinViewArray};
123124
use crate::compute::{Operator, compare};
124125

125126
#[test]
@@ -146,4 +147,25 @@ mod test {
146147
&BooleanBuffer::from_iter([true, false, false])
147148
);
148149
}
150+
151+
#[test]
152+
fn varbinview_compare() {
153+
let array = VarBinArray::from_iter(
154+
[Some(b"abc".to_vec()), None, Some(b"def".to_vec())],
155+
DType::Binary(Nullability::Nullable),
156+
);
157+
let vbv = VarBinViewArray::from_iter(
158+
[None, None, Some(b"def".to_vec())],
159+
DType::Binary(Nullability::Nullable),
160+
);
161+
let result = compare(array.as_ref(), vbv.as_ref(), Operator::Eq)
162+
.unwrap()
163+
.to_bool()
164+
.unwrap();
165+
166+
assert_eq!(
167+
result.boolean_buffer(),
168+
&BooleanBuffer::from_iter([false, true, true])
169+
);
170+
}
149171
}

0 commit comments

Comments
 (0)