You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "rluvaton (via GitHub)" <gi...@apache.org> on 2026/06/09 12:09:38 UTC
[PR] feat(lambda): support map non empty nulls cleanup for `HigherOrderFunctionExpr` [datafusion]
rluvaton opened a new pull request, #22847:
URL: https://github.com/apache/datafusion/pull/22847
## Which issue does this PR close?
- Closes #22846
## Rationale for this change
Just extending support so common pitfalls can be prevented for map as well
see:
- https://github.com/apache/datafusion/pull/22689
## What changes are included in this PR?
created custom `cleanup_non_empty` null values that handle maps as well and fallback for `remove_list_null_values` for list
I done this like this as I plan to remove this function once this arrow pr is merged and released:
- https://github.com/apache/arrow-rs/pull/9970
## Are these changes tested?
Yes
## Are there any user-facing changes?
Yes, support map cleanup, updated docs
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat(lambda): support map non empty nulls cleanup for `HigherOrderFunctionExpr` [datafusion]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #22847:
URL: https://github.com/apache/datafusion/pull/22847#issuecomment-5229320101
Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat(lambda): support map non empty nulls cleanup for `HigherOrderFunctionExpr` [datafusion]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #22847: feat(lambda): support map non empty nulls cleanup for `HigherOrderFunctionExpr`
URL: https://github.com/apache/datafusion/pull/22847
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] feat(lambda): support map non empty nulls cleanup for `HigherOrderFunctionExpr` [datafusion]
Posted by "rluvaton (via GitHub)" <gi...@apache.org>.
rluvaton commented on code in PR #22847:
URL: https://github.com/apache/datafusion/pull/22847#discussion_r3380456755
##########
datafusion/physical-expr/src/higher_order_function.rs:
##########
@@ -503,8 +503,87 @@ fn wrapped_lambda(expr: &Arc<dyn PhysicalExpr>) -> Option<&LambdaExpr> {
}
}
+
+fn support_clear_non_empty_null_values(data_type: &DataType) -> bool {
+ match data_type {
+ DataType::List(_) | DataType::LargeList(_) | DataType::Map(_, _) => true,
+ _ => false,
+ }
+}
+
+/// For lists and large lists, truncates the sublist of null values
+/// For maps, truncates the submaps of null values
+/// Otherwise returns an error
+fn remove_non_empty_null_values(array: &ArrayRef) -> Result<ArrayRef> {
+ // todo: handle list view
+ let array = match array.data_type() {
+ DataType::List(_) | DataType::LargeList(_) => remove_list_null_values(array)? as ArrayRef,
+ DataType::Map(_, _) => Arc::new(remove_map_non_empty_null_values(array)?) as ArrayRef,
+ dt => {
+ assert!(!support_clear_non_empty_null_values(dt), "data type marked as supported but not implemented");
+ return _exec_err!("expected List/LargeList/Map, got {dt}")
+ },
+ };
+
+ assert!(support_clear_non_empty_null_values(array.data_type()), "data type marked as not supported but implemented");
+
+ Ok(array)
+}
+
+fn remove_map_non_empty_null_values(map: &MapArray) -> Result<MapArray> {
+ if let Some(nulls) = map.nulls()
+ && nulls.null_count() > 0
+ {
+ let lengths = Int32Array::from_iter(map.offsets().lengths().zip(nulls.iter()).map(|(len, is_valid)| if is_valid { Some(len as i32)} else {None}));
+ let zero: &dyn Datum = &Int32Array::new_scalar(0);
+
+ let (mut valid_or_empty, _nulls) = eq(&lengths, zero)?.into_parts();
+ valid_or_empty |= nulls.inner();
+ let valid_or_empty = BooleanArray::from(valid_or_empty);
+
+ if valid_or_empty.has_false() {
+ let array_data = map.entries().to_data();
+ let offsets = map.offsets();
+ let capacity = offsets[offsets.len() - 1] - offsets[0];
+ let mut mutable_array_data =
+ MutableArrayData::new(vec![&array_data], false, capacity as usize);
+
+ let (valid_or_empty, _nulls) = valid_or_empty.into_parts();
+
+ for (start, end) in valid_or_empty.set_slices() {
+ mutable_array_data.extend(
+ 0,
+ offsets[start] as usize,
+ offsets[end] as usize
+ );
+ }
+
+ let lengths = std::iter::zip(offsets.lengths(), nulls)
+ .map(|(length, is_valid)| if is_valid { length } else { 0 });
+
+ let offsets = OffsetBuffer::from_lengths(lengths);
+ let entries = make_array(mutable_array_data.freeze());
+ let entries = entries.as_struct().clone();
+
+ let DataType::Map(field, ordered) = map.data_type() else {
+ unreachable!("map array data type is not Map");
+ };
+
+ return Ok(MapArray::try_new(
+ Arc::clone(field),
+ offsets,
+ entries,
+ map.nulls().cloned(),
+ *ordered
+ )?);
+ }
+ }
+ Ok(map.clone())
+}
Review Comment:
I want to remove this once my arrow pr that does that is merged and released:
- https://github.com/apache/arrow-rs/pull/9970
so I did not make it public or modify the old function to make sure to not increase the breaking change scope when removing this function and the `remove_list_null_values`
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org