Jefffrey commented on code in PR #24582:
URL: https://github.com/apache/datafusion/pull/24582#discussion_r3840922716
##########
datafusion/common/src/scalar/mod.rs:
##########
@@ -5035,16 +5041,23 @@ impl ScalarValue {
DataType::BinaryView => Arc::new(array.as_binary_view().gc()),
DataType::Struct(_) => {
let s = array.as_struct();
- let columns = s
- .columns()
- .iter()
- .map(|c| ScalarValue::compact_view_buffers(Arc::clone(c)))
- .collect();
- Arc::new(StructArray::new(
- s.fields().clone(),
- columns,
- s.nulls().cloned(),
- ))
+ if s.fields().is_empty() {
+ Arc::new(StructArray::new_empty_fields(
+ s.len(),
+ s.nulls().cloned(),
+ ))
Review Comment:
could probably clone the input instead of reconstructing?
##########
datafusion/common/src/scalar/mod.rs:
##########
@@ -11607,4 +11620,86 @@ mod tests {
);
assert_eq!(&large_list.value(0), &expected_array);
}
+
+ #[test]
+ fn test_compact_empty_struct() {
+ let nulls = NullBuffer::from(vec![true, false, true]);
+ let empty_struct = Arc::new(StructArray::new_empty_fields(3,
Some(nulls)));
+ let mut scalar = ScalarValue::Struct(empty_struct);
+
+ // Before fix: panics inside compact_view_buffers calling
StructArray::new on 0 fields
+ scalar.compact();
Review Comment:
seems a bit odd that a scalar would have 3 rows
--
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]