Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array take doesn't make fields nullable #6809

Closed
midnattsol opened this issue Nov 28, 2024 · 1 comment
Closed

Array take doesn't make fields nullable #6809

midnattsol opened this issue Nov 28, 2024 · 1 comment
Labels

Comments

@midnattsol
Copy link

Describe the bug

When calling arrow::compute::take on an Array with non-nullable fields and passing take indices that contain null values, the resulting Array contains null values. This is an invalid state.

To Reproduce

use arrow::array::Array;
use arrow::array::{Int32Array, StringArray, StructArray};
use arrow::compute::take;
use arrow::datatypes::{DataType, Field};
use std::sync::Arc;

fn main() {
    // Crear un StructArray con campos no anulables
    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>,
        ),
    ]);

    // // Create an array of indices with null values
    let indices = Int32Array::from(vec![Some(0), None, Some(2)]);

    let field1_column = struct_array.column_by_name("field1").unwrap();
    let field1_result = take(field1_column, &indices, None).unwrap();
    let field1_result = field1_result.as_any().downcast_ref::<Int32Array>().unwrap();
    println!("Result field1: {:?}", field1_result);

    let field2_column = struct_array.column_by_name("field2").unwrap();
    let field2_result = take(field2_column, &indices, None).unwrap();
    let field2_result = field2_result
        .as_any()
        .downcast_ref::<StringArray>()
        .unwrap();
    println!("Result field2: {:?}", field2_result);
}

Output

Result field1: PrimitiveArray<Int32>
[
  1,
  null,
  3,
]
Result field2: StringArray
[
  "a",
  null,
  "c",
]

Expected behavior
Using take with null indices on Array with no-nullable values should return an error.

Additional context
This issue is related with this one #6727

@midnattsol
Copy link
Author

Duplicated, it can be solved with a small change in the issue #6727

@midnattsol midnattsol closed this as not planned Won't fix, can't repro, duplicate, stale Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant