sesteves opened a new issue, #27012:
URL: https://github.com/apache/datafusion/issues/27012

   `map_entries()` panics when the map value field is declared non-nullable. 
The same input works when the value field is nullable.
   
   ### Reproducer
   
   ```rust
   use std::sync::Arc;
   
   use datafusion::arrow::array::{Array, ArrayRef, MapArray, StringArray, 
StructArray};
   use datafusion::arrow::buffer::OffsetBuffer;
   use datafusion::arrow::datatypes::{DataType, Field, Fields};
   use datafusion::functions_nested::map_entries::MapEntriesFunc;
   use datafusion::logical_expr::{ColumnarValue, ScalarFunctionArgs, 
ScalarUDFImpl};
   
   fn main() {
       let fields = Fields::from(vec![
           Field::new("key", DataType::Utf8, false),
           Field::new("value", DataType::Utf8, false),
       ]);
       let entries = StructArray::new(
           fields.clone(),
           vec![
               Arc::new(StringArray::from(vec!["k"])) as ArrayRef,
               Arc::new(StringArray::from(vec!["v"])) as ArrayRef,
           ],
           None,
       );
       let map = MapArray::new(
           Arc::new(Field::new("entries", DataType::Struct(fields), false)),
           OffsetBuffer::new(vec![0_i32, 1].into()),
           entries,
           None,
           false,
       );
   
       let udf = MapEntriesFunc::new();
       let return_type = udf.return_type(&[map.data_type().clone()]).unwrap();
       udf.invoke_with_args(ScalarFunctionArgs {
           arg_fields: vec![Arc::new(Field::new("m", map.data_type().clone(), 
true))],
           args: vec![ColumnarValue::Array(Arc::new(map))],
           number_rows: 1,
           return_field: Arc::new(Field::new("result", return_type, true)),
           config_options: Arc::new(Default::default()),
       })
       .unwrap();
   }
   ```
   
   ### Actual
   
   ```text
   InvalidArgumentError("ListArray expected data type
   Struct(\"key\": non-null Utf8, \"value\": Utf8)
   got Struct(\"key\": non-null Utf8, \"value\": non-null Utf8)
   for \"item\"")
   ```
   
   ### Expected
   
   `[{key: "k", value: "v"}]`
   
   Reproduced on 54.1.0. From reading the source, 
[55.2.0](https://github.com/apache/datafusion/blob/55.2.0/datafusion/functions-nested/src/map_entries.rs#L126-L137)
 and current `main` still have the same code. The function makes the output 
value field nullable but reuses the non-nullable input entries.
   


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to