midnattsol commented on issue #6727:
URL: https://github.com/apache/arrow-rs/issues/6727#issuecomment-2503547698
Hello, I'd be happy to work on this.
I'm already making some tests, adding the validation to the struct datatype:
```rust
DataType::Struct(fields) => {
let array: &StructArray = values.as_struct();
for (field, _) in fields.iter().zip(array.columns()) {
if !field.is_nullable() && indices.null_count() > 0 {
return Err(ArrowError::ComputeError(format!(
"Cannot introduce nulls in non-nullable field '{}'",
field.name()
)));
}
}
```
Testing it, it seems to work when I try to use take over a StructArray:
```rust
use arrow::array::{Int32Array, StringArray, StructArray};
use arrow::compute::take;
use arrow::datatypes::{DataType, Field};
use std::sync::Arc;
fn main() {
let field1 = Int32Array::from(vec![Some(1), Some(2), Some(3)]);
let field2 = StringArray::from(vec![Some("a"), Some("b"), Some("c")]);
let struct_array = StructArray::from(vec![
(
Arc::new(Field::new("field1", DataType::Int32, false)),
Arc::new(field1) as Arc<dyn arrow::array::Array>,
),
(
Arc::new(Field::new("field2", DataType::Utf8, false)),
Arc::new(field2) as Arc<dyn arrow::array::Array>,
),
]);
let indices = Int32Array::from(vec![Some(0), None, Some(2)]);
// Aplicar la función take
let result = take(&struct_array, &indices, None).unwrap();
let result_struct =
result.as_any().downcast_ref::<StructArray>().unwrap();
println!("Resultado StructArray: {:?}", result_struct);
```
**Result**
```sh
Running `target/debug/arrow-playground`
thread 'main' panicked at src/main.rs:25:54:
called `Result::unwrap()` on an `Err` value: ComputeError("Cannot introduce
nulls in non-nullable field 'field1'")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
But when I try to use take over specific Fields, the issue stays the same. I
can try to solve this too, but I just want to be sure that I'm not
misanderstanding anything.
I would appreciate feedback, it's my first issue related with `Arrow`
ecosystem.
Regards
--
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]