[ 
https://issues.apache.org/jira/browse/ARROW-9503?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Ritchie updated ARROW-9503:
---------------------------
    Description: 
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.



  was:
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:test}
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.




> 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)

Reply via email to