rust/sedona-testing: Update assert_array_equal to accept a SedonaType parameter for better failures
- Dominant language
- Rust
- Stars
- 503
- Forks
- 61
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 90
Description
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:
```rust
/// 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).
Contributor guide
Research direction
Start by locating `assert_array_equal` and its call sites in `rust/sedona-testing`. Update the affected tests to provide a `SedonaType` context, then run the relevant test suite and confirm that geometry-array failures use readable messages and all tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- testing-qa
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100