Skip to content

rust/sedona-testing: Update assert_array_equal to accept a SedonaType parameter for better failures #518

@paleolimbot

Description

@paleolimbot

Currently failures from assert_array_equal() are very bad binary strings. This is a relict from a much, much earlier version of SedonaDB where our ArrayRef had the full extension type embedded and could detect the geometry case. Now we need a parameter:

/// Assert two [`ArrayRef`]s are equal with SedonaType context
///
/// Panics if the values' length or types are different or if the content is otherwise not
/// equal. This can be used in place of `assert_eq!()` to generate reasonable
/// failure messages for geometry arrays where the default failure message would
/// otherwise be uninformative.
pub fn assert_array_equal(actual: &ArrayRef, expected: &ArrayRef, sedona_type: &SedonaType) {
    if actual.data_type() != sedona_type.storage_type() {
        panic!(
            "expected storage type != {sedona_type} storage type ({})",
            sedona_type.storage_type()
        );
    }

    if actual.data_type() != sedona_type.storage_type() {
        panic!(
            "actual storage type != {sedona_type} storage type ({})",
            sedona_type.storage_type()
        );
    }

    if actual.len() != expected.len() {
        panic!(
            "Lengths not equal: actual Array has length {}, expected Array has length {}",
            actual.len(),
            expected.len()
        )
    }

    match sedona_type {
        SedonaType::Arrow(_) => {
            assert_eq!(actual, expected)
        }

        SedonaType::Wkb(_, _) => {
            assert_wkb_sequences_equal(
                as_binary_array(&actual).unwrap(),
                as_binary_array(&expected).unwrap(),
            );
        }
        SedonaType::WkbView(_, _) => {
            assert_wkb_sequences_equal(
                as_binary_view_array(&actual).unwrap(),
                as_binary_view_array(&expected).unwrap(),
            );
        }
        unsupported => {
            panic!("SedonaType comparison for {unsupported} is not supported");
        }
    }
}

This change requires a lot of changes in tests but they should be straightfoward (I adapted this function whilst attempting to debug a failure of my own in a PR).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions