apache / arrow-rs

Official Rust implementation of Apache Arrow
https://arrow.apache.org/
Apache License 2.0
2.31k stars 678 forks source link

arrow-ord: Comparison for struct #5411

Open jayzhan211 opened 4 months ago

jayzhan211 commented 4 months ago

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

Describe the solution you'd like

similar to #5407 but for struct We can have eq first which fix https://github.com/apache/arrow-datafusion/issues/9254

Pass this test

    #[test]
    fn test_struct_ord() {
        let s1 = StructArray::try_from(vec![
            (
                "a",
                Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5])) as Arc<dyn Array>,
            ),
            (
                "b",
                Arc::new(Float32Array::from(vec![1.0, 2.0, 3.0, 4.0, 5.0])) as Arc<dyn Array>,
            )
        ]).unwrap();
        let s2 = StructArray::try_from(vec![
            (
                "a",
                Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5])) as Arc<dyn Array>,
            ),
            (
                "b",
                Arc::new(Float32Array::from(vec![1.0, 2.0, 3.0, 4.0, 5.0])) as Arc<dyn Array>,
            )
        ]).unwrap();

        let res = eq(&s1, &s2).unwrap();
        println!("res: {:?}", res);
    }

Describe alternatives you've considered

Additional context

tustvold commented 4 months ago

This should be a relatively straightforward case of recursing for each of the fields and then combining the results based on the operation. Unlike ListArray, it shouldn't necessary to use DynComparator as the indices to compare are aligned