[
https://issues.apache.org/jira/browse/ARROW-9503?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17159145#comment-17159145
]
Chao Sun commented on ARROW-9503:
---------------------------------
I think its because
[{{comparison.rs}}|https://github.com/apache/arrow/blob/master/rust/arrow/src/compute/kernels/comparison.rs#L61]
uses the offset of the input slice as the result array offset:
{code}
/// Helper function to perform boolean lambda function on values from two
arrays, this
/// version does not attempt to use SIMD.
macro_rules! compare_op {
($left: expr, $right:expr, $op:expr) => {{
if $left.len() != $right.len() {
return Err(ArrowError::ComputeError(
"Cannot perform comparison operation on arrays of different
length"
.to_string(),
));
}
let null_bit_buffer = apply_bin_op_to_option_bitmap(
$left.data().null_bitmap(),
$right.data().null_bitmap(),
|a, b| a & b,
)?;
let mut result = BooleanBufferBuilder::new($left.len());
for i in 0..$left.len() {
result.append($op($left.value(i), $right.value(i)))?;
}
let data = ArrayData::new(
DataType::Boolean,
$left.len(),
None,
null_bit_buffer,
$left.offset(),
vec![result.finish()],
vec![],
);
Ok(PrimitiveArray::<BooleanType>::from(Arc::new(data)))
}};
}
{code}
Seems it should always use 0 as result array offset, as it constructs a new
boolean array and return it here.
> Comparison sliced arrays is wrong
> ---------------------------------
>
> Key: ARROW-9503
> URL: https://issues.apache.org/jira/browse/ARROW-9503
> Project: Apache Arrow
> Issue Type: Bug
> Components: Rust
> Reporter: Ritchie
> Priority: Major
>
> Comparison of arrow arrays where one is sliced is dependent on the order of
> comparison, and doesn't always yield correct results.
> The following minimal example shows the differing results.
> {code:rust}
> use arrow::{
> datatypes::Int32Type,
> compute,
> array::{
> Array,
> PrimitiveBuilder,
> PrimitiveArray
> }
> };
> let mut builder = PrimitiveBuilder::new(10);
> for v in 0..10 {
> builder.append_value(v).unwrap()
> }
> let a: PrimitiveArray<Int32Type> = builder.finish();
> let mut builder = PrimitiveBuilder::new(10);
> for v in 5..10 {
> builder.append_value(v).unwrap()
> }
> let b: PrimitiveArray<Int32Type> = builder.finish();
> // returns Array trait
> let sliced_a = a.slice(5, 5);
> // Downcast to PrimitiveArray
> let sliced_a = sliced_a.as_any().downcast_ref().unwrap();
> println!("{:?}", a.slice(5, 5));
> println!("{:?}", b);
> println!("{:?}", compute::eq(sliced_a, &b));
> println!("{:?}", compute::eq(&b, sliced_a))
> {code}
> This prints:
> {code:text}
> PrimitiveArray<Int32>
> [
> 5,
> 6,
> 7,
> 8,
> 9,
> ]
> PrimitiveArray<Int32>
> [
> 5,
> 6,
> 7,
> 8,
> 9,
> ]
> Ok(PrimitiveArray<Boolean>
> [
> false,
> false,
> false,
> false,
> false,
> ])
> Ok(PrimitiveArray<Boolean>
> [
> true,
> true,
> true,
> true,
> true,
> ])
> {code}
> I would expect both comparison arrays to evaluate to true. This same effect
> is also occurring with utf8arrays.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)