Jefffrey commented on code in PR #22285:
URL: https://github.com/apache/datafusion/pull/22285#discussion_r3301781440
##########
datafusion/functions-nested/src/arrays_zip.rs:
##########
@@ -327,3 +332,226 @@ fn arrays_zip_inner(args: &[ArrayRef]) ->
Result<ArrayRef> {
Ok(Arc::new(result))
}
+
+fn arrays_zip_field_name(index: usize) -> String {
+ (index + 1).to_string()
+}
+
+fn arrays_zip_field_names(len: usize) -> Vec<String> {
+ (0..len).map(arrays_zip_field_name).collect()
+}
+
+/// Fast path for regular List inputs whose existing buffers already match the
+/// zipped output: all offsets and values lengths match, and null rows cover no
+/// values. This lets us reuse offsets and child values instead of rebuilding.
+fn try_perfect_list_zip(
+ args: &[ArrayRef],
+ field_names: &[String],
+) -> Result<Option<ArrayRef>> {
+ debug_assert_eq!(args.len(), field_names.len());
+
+ let mut list_arrays = Vec::with_capacity(args.len());
+ let mut struct_fields = Vec::with_capacity(args.len());
+
+ for (arg, field_name) in args.iter().zip(field_names) {
+ let arr = match arg.data_type() {
+ List(field) => {
+ struct_fields.push(Field::new(
+ field_name.clone(),
+ field.data_type().clone(),
+ true,
+ ));
+ as_list_array(arg)?
+ }
+ _ => return Ok(None),
+ };
+
+ list_arrays.push(arr);
+ }
+
+ let first = list_arrays[0];
+ let num_rows = first.len();
+ let offsets = first.offsets().clone();
+ let values_len = first.values().len();
+
+ // Reusing the child arrays is only valid when every list uses the exact
+ // same row boundaries and exposes the same total number of child values.
+ for arr in &list_arrays {
+ if arr.len() != num_rows
Review Comment:
num row check here isn't necessary, as by now its a guarantee all input
arrays are of same length
##########
datafusion/functions-nested/src/arrays_zip.rs:
##########
@@ -327,3 +332,226 @@ fn arrays_zip_inner(args: &[ArrayRef]) ->
Result<ArrayRef> {
Ok(Arc::new(result))
}
+
+fn arrays_zip_field_name(index: usize) -> String {
+ (index + 1).to_string()
+}
+
+fn arrays_zip_field_names(len: usize) -> Vec<String> {
+ (0..len).map(arrays_zip_field_name).collect()
+}
+
+/// Fast path for regular List inputs whose existing buffers already match the
+/// zipped output: all offsets and values lengths match, and null rows cover no
+/// values. This lets us reuse offsets and child values instead of rebuilding.
+fn try_perfect_list_zip(
+ args: &[ArrayRef],
+ field_names: &[String],
+) -> Result<Option<ArrayRef>> {
+ debug_assert_eq!(args.len(), field_names.len());
+
+ let mut list_arrays = Vec::with_capacity(args.len());
+ let mut struct_fields = Vec::with_capacity(args.len());
+
+ for (arg, field_name) in args.iter().zip(field_names) {
+ let arr = match arg.data_type() {
+ List(field) => {
+ struct_fields.push(Field::new(
+ field_name.clone(),
+ field.data_type().clone(),
+ true,
+ ));
+ as_list_array(arg)?
+ }
+ _ => return Ok(None),
+ };
+
+ list_arrays.push(arr);
+ }
+
+ let first = list_arrays[0];
+ let num_rows = first.len();
+ let offsets = first.offsets().clone();
+ let values_len = first.values().len();
+
+ // Reusing the child arrays is only valid when every list uses the exact
+ // same row boundaries and exposes the same total number of child values.
+ for arr in &list_arrays {
+ if arr.len() != num_rows
+ || arr.values().len() != values_len
+ || arr.offsets() != &offsets
+ {
+ return Ok(None);
+ }
+ }
+
+ let nulls = if list_arrays.iter().any(|arr| arr.null_count() != 0) {
Review Comment:
I think we can construct nulls just with
[`NullBuffer::union_many`](https://docs.rs/arrow/latest/arrow/buffer/struct.NullBuffer.html#method.union_many)
Reason being by this point we've verified all offsets are equal for the
arrays, so even if we have a non-zero sized null I think this is fine since
offsets still align?
--
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]