grorge123 commented on code in PR #5526:
URL: https://github.com/apache/datafusion-comet/pull/5526#discussion_r4196016306
##########
native/core/src/execution/planner.rs:
##########
@@ -6570,6 +6570,70 @@ mod tests {
Ok(())
}
+ #[test]
+ fn test_literal_to_list_with_only_empty_children() -> Result<(),
DataFusionError> {
+ // [[], null]: no child contributes values, so the values array is
built empty. It must
+ // still have the child list's element type, as it does when some
child is non-empty.
+ let data = ListLiteral {
+ list_values: vec![ListLiteral::default(), ListLiteral::default()],
+ null_mask: vec![true, false],
+ ..Default::default()
+ };
+ let inner = DataType::List(Arc::new(Field::new("item",
DataType::Int64, true)));
+ let nested_type = DataType::List(Arc::new(Field::new("item",
inner.clone(), true)));
+
+ let array = literal_to_array_ref(nested_type, data)?;
+ assert_eq!(array.data_type(), &inner);
+ let list = array.as_any().downcast_ref::<ListArray>().unwrap();
+ assert_eq!(list.len(), 2);
+ assert!(list.value(0).is_empty());
+ assert!(list.is_null(1));
+
+ // [[[]], [[[1]]]] with every declared field non-nullable: the first
child has no values
+ // below its own level, the second has. Both must come out as the same
type, or
+ // concatenating them fails.
+ let list_of = |dt: DataType|
DataType::List(Arc::new(Field::new("item", dt, false)));
+ let one = ListLiteral {
+ int_values: vec![1],
+ null_mask: vec![true],
+ ..Default::default()
+ };
+ let data = ListLiteral {
+ list_values: vec![
+ ListLiteral {
+ list_values: vec![ListLiteral::default()],
+ null_mask: vec![true],
+ ..Default::default()
+ },
+ ListLiteral {
+ list_values: vec![ListLiteral {
+ list_values: vec![one],
+ null_mask: vec![true],
+ ..Default::default()
+ }],
+ null_mask: vec![true],
+ ..Default::default()
+ },
+ ],
+ null_mask: vec![true, true],
+ ..Default::default()
+ };
+ let nested_type = list_of(list_of(list_of(list_of(DataType::Int32))));
+
+ let array = literal_to_array_ref(nested_type, data)?;
+ let list = array.as_any().downcast_ref::<ListArray>().unwrap();
+ assert_eq!(list.len(), 2);
+ assert!(list
+ .value(0)
+ .as_any()
+ .downcast_ref::<ListArray>()
+ .unwrap()
+ .value(0)
+ .is_empty());
+ assert_eq!(list.value(1).len(), 1);
+ Ok(())
Review Comment:
Agreed, 267b5ce drops it and keeps only the `[[], null]` case.
--
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]