AdamGS commented on code in PR #25122:
URL: https://github.com/apache/datafusion/pull/25122#discussion_r3988076302


##########
datafusion/functions/src/core/getfield.rs:
##########
@@ -236,9 +251,19 @@ fn extract_single_field(base: ColumnarValue, name: 
ScalarValue) -> Result<Column
         }
         (DataType::Struct(_), _, Some(k)) => {
             let as_struct_array = as_struct_array(&array)?;
-            match as_struct_array.column_by_name(&k) {
-                None => exec_err!("Field {k} not found in struct"),
-                Some(col) => Ok(ColumnarValue::Array(Arc::clone(col))),
+            let nulls = as_struct_array.nulls();
+            match (as_struct_array.column_by_name(&k), nulls) {
+                (None, _) => exec_err!("Field {k} not found in struct"),
+                (Some(col), None) => Ok(ColumnarValue::Array(Arc::clone(col))),
+                (Some(col), Some(parent_nulls)) => {
+                    // NullArray is already entirely null and cannot have a 
validity bitmap.
+                    if col.data_type().is_null() {
+                        return Ok(ColumnarValue::Array(Arc::clone(col)));
+                    }
+                    let nulls = NullBuffer::union(col.nulls(), 
Some(parent_nulls));
+                    let data = 
col.to_data().into_builder().nulls(nulls).build()?;

Review Comment:
   Nice find! I'll add the test and a fix



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