alamb opened a new issue #2117: URL: https://github.com/apache/arrow-datafusion/issues/2117
**Describe the bug** Running certain queries with `CASE` expressions will result in an error such as: ``` thread 'main' panicked at 'range end index 3 out of range for slice of length 2', /Users/alamb/.cargo/registry/src/github.com-1ecc6299db9ec823/arrow-11.0.0/src/array/transform/primitive.rs:31:37 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` @yjshen basically has identified the issue here: https://github.com/influxdata/influxdb_iox/pull/4148#issuecomment-1081563527 related to Nulls and `SlicesIter` **To Reproduce** ```rust use std::sync::Arc; use datafusion::{arrow::{array::{ArrayRef, Float64Array, Array, ArrayDataBuilder}, util::pretty, record_batch::RecordBatch, buffer::Buffer}, prelude::*, datasource::MemTable}; #[tokio::main] async fn main() { println!("Starting tests"); // Construct an array that has several NULL values whose // underlying buffer actually matches the where expr predicate let load4: Float64Array = vec![ Some(1.77), // 1.77 Some(1.77), // null <-- matching, but will be set to null Some(1.77), // null <-- matching, but will be set to null Some(1.78), // 1.78 None, // null Some(1.77), // 1.77 ].into_iter() .collect(); let null_buffer = Buffer::from_slice_ref(&[0b00101001u8]); let load4 = ArrayDataBuilder::new(load4.data_type().clone()) .len(load4.len()) .null_bit_buffer(null_buffer) .buffers(load4.data().buffers().to_vec()) .build() .unwrap(); let load4: Float64Array = load4.into(); let batch = RecordBatch::try_from_iter(vec![ ("load4", Arc::new(load4) as ArrayRef), ]).unwrap(); let config = SessionConfig::new(); let ctx = SessionContext::with_config(config); let table = MemTable::try_new(batch.schema(), vec![vec![batch]]).unwrap(); ctx.register_table("foo", Arc::new(table)).unwrap(); let df = ctx.sql("SELECT * FROM foo").await.expect("sql"); let batches = df.collect().await.expect("execute"); pretty::print_batches(&batches).unwrap(); // this panic's // thread 'main' panicked at 'range end index 3 out of range for slice of length 2', /Users/alamb/.cargo/registry/src/github.com-1ecc6299db9ec823/arrow-11.0.0/src/array/transform/primitive.rs:31:37 let df = ctx.sql("SELECT CASE WHEN load4 = 1.77 THEN load4 END as load4 FROM foo").await.expect("sql"); let batches = df.collect().await.expect("execute"); pretty::print_batches(&batches).unwrap(); } ``` results in **Expected behavior** This output should be produced ``` 1.77 NULL NULL NULL NULL 1.77 ``` **Additional context** Very likely introduced by https://github.com/apache/arrow-datafusion/pull/2068 Found by the IOx test suite here: https://github.com/influxdata/influxdb_iox/pull/4148 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
