Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

SliceIterator of last bytes is not correct #292

Closed
ritchie46 opened this issue Aug 17, 2021 · 0 comments · Fixed by #293
Closed

SliceIterator of last bytes is not correct #292

ritchie46 opened this issue Aug 17, 2021 · 0 comments · Fixed by #293
Labels
bug Something isn't working

Comments

@ritchie46
Copy link
Collaborator

ritchie46 commented Aug 17, 2021

This slicing stress test will make us more sure of the future. 🙂 (once it passes)

Cargo.toml

[dependencies]
arrow = { package = "arrow2", git = "https://github.com/jorgecarleitao/arrow2", rev = "86edfd639b33d9fbc468e2f68bb6ce41de52f95e", default-features = false, features=["compute"]}
rand = "0.8"

main.rs

use rand::Rng;
use arrow::array::{Utf8Array, BooleanArray, Array};
use rand::distributions::{
    Alphanumeric, Uniform, Bernoulli
};
use arrow::compute::filter::filter;
use std::iter::FromIterator;

fn main() {
    let mut rng = rand::thread_rng();
    let length = 50000;

    let values_iter = (0..length).map(|_| {
        let len = (&mut rng).sample(Uniform::new(0usize, 8));
        let s: String = (&mut rng).sample_iter(&Alphanumeric).take(len).map(char::from).collect();
        s
    });


    let arr = Utf8Array::<i32>::from_iter_values(values_iter);
    let values_iter = (0..length).map(|_| {
        let v: bool = (&mut rng).sample(Bernoulli::new(0.5).unwrap());
        Some(v)
    });
    let mask = BooleanArray::from_iter(values_iter);

    for offset in 100usize..(length - 1) {
        let len = (&mut rng).sample(Uniform::new(0, length - offset));
        let arr_s = arr.slice(offset, len);
        let mask_s = mask.slice(offset, len);

        filter(&arr_s, &mask_s).unwrap();
    }
}

Run

RUST_BACKTRACE=1 cargo run --release

Panic

thread 'main' panicked at 'range end index 41006 out of range for slice of length 41001', /home/ritchie46/.cargo/git/checkouts/arrow2-8a2ad61d97265680/86edfd6/src/array/growable/utf8.rs:75:14
stack backtrace:
   0: rust_begin_unwind
             at /rustc/492723897e9b4db6701b3a75b72618d08a7d5319/library/std/src/panicking.rs:516:5
   1: core::panicking::panic_fmt
             at /rustc/492723897e9b4db6701b3a75b72618d08a7d5319/library/core/src/panicking.rs:93:14
   2: core::slice::index::slice_end_index_len_fail
             at /rustc/492723897e9b4db6701b3a75b72618d08a7d5319/library/core/src/slice/index.rs:41:5
   3: <core::ops::range::Range<usize> as core::slice::index::SliceIndex<[T]>>::index
             at /rustc/492723897e9b4db6701b3a75b72618d08a7d5319/library/core/src/slice/index.rs:240:13
   4: core::slice::index::<impl core::ops::index::Index<I> for [T]>::index
             at /rustc/492723897e9b4db6701b3a75b72618d08a7d5319/library/core/src/slice/index.rs:15:9
   5: <arrow2::array::growable::utf8::GrowableUtf8<O> as arrow2::array::growable::Growable>::extend
             at /home/ritchie46/.cargo/git/checkouts/arrow2-8a2ad61d97265680/86edfd6/src/array/growable/utf8.rs:75:14
   6: arrow2::compute::filter::filter::{{closure}}
             at /home/ritchie46/.cargo/git/checkouts/arrow2-8a2ad61d97265680/86edfd6/src/compute/filter.rs:244:42
   7: core::iter::traits::iterator::Iterator::for_each::call::{{closure}}
             at /rustc/492723897e9b4db6701b3a75b72618d08a7d5319/library/core/src/iter/traits/iterator.rs:734:29
   8: core::iter::traits::iterator::Iterator::fold
             at /rustc/492723897e9b4db6701b3a75b72618d08a7d5319/library/core/src/iter/traits/iterator.rs:2174:21
   9: core::iter::traits::iterator::Iterator::for_each
             at /rustc/492723897e9b4db6701b3a75b72618d08a7d5319/library/core/src/iter/traits/iterator.rs:737:9
  10: arrow2::compute::filter::filter
             at /home/ritchie46/.cargo/git/checkouts/arrow2-8a2ad61d97265680/86edfd6/src/compute/filter.rs:244:13
  11: memcheck::main
             at ./src/main.rs:32:9
  12: core::ops::function::FnOnce::call_once
             at /rustc/492723897e9b4db6701b3a75b72618d08a7d5319/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@jorgecarleitao jorgecarleitao added the bug Something isn't working label Aug 17, 2021
@jorgecarleitao jorgecarleitao changed the title slice and dice stresstest Utf8Array SliceIterator of last bytes is not correct Aug 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants