timsaucer commented on code in PR #24365:
URL: https://github.com/apache/datafusion/pull/24365#discussion_r3784051844
##########
datafusion/functions-nested/src/utils.rs:
##########
@@ -35,6 +35,57 @@ use datafusion_common::{Result, ScalarValue, exec_err,
internal_err, plan_err};
use datafusion_expr::ColumnarValue;
use itertools::Itertools as _;
+/// Computes the return type of a function that produces a list with the same
+/// inner field as `array_type`, plus an element that may be null when
+/// `element_nullable` is set.
+///
+/// The inner field is carried over from `array_type` verbatim — name, metadata
+/// and all — so that the type promised at planning time is the one the kernel
+/// can actually build. Its nullability is widened when `element_nullable` is
+/// set, because a nullable new element may introduce nulls into a list whose
+/// elements were previously declared non-nullable.
+///
+/// Types other than `List`/`LargeList` are returned unchanged; callers handle
+/// `Null` themselves and the kernels reject anything else at execution time.
+pub(crate) fn list_type_with_element(
+ array_type: &DataType,
+ element_nullable: bool,
+) -> DataType {
+ match array_type {
+ DataType::List(field) => {
+ DataType::List(widen_nullability(field, element_nullable))
+ }
+ DataType::LargeList(field) => {
+ DataType::LargeList(widen_nullability(field, element_nullable))
+ }
+ other => other.clone(),
+ }
+}
Review Comment:
This is important because if I append a nullable element to a list of
non-nullable elements then the output should be a list of nullable elements.
--
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]