Dandandan commented on code in PR #7517:
URL: https://github.com/apache/arrow-rs/pull/7517#discussion_r2096385192
##########
arrow-select/src/concat.rs:
##########
@@ -231,6 +231,45 @@ fn concat_bytes<T: ByteArrayType>(arrays: &[&dyn Array])
-> Result<ArrayRef, Arr
Ok(Arc::new(builder.finish()))
}
+fn concat_structs(arrays: &[&dyn Array], fields: &Fields) -> Result<ArrayRef,
ArrowError> {
+ let mut len = 0;
+ let mut has_nulls = false;
+ let structs = arrays
+ .iter()
+ .map(|a| {
+ len += a.len();
+ has_nulls |= a.null_count() > 0;
+ a.as_struct()
+ })
+ .collect::<Vec<_>>();
+
+ let nulls = has_nulls.then(|| {
+ let mut b = BooleanBufferBuilder::new(len);
+ for s in &structs {
+ match s.nulls() {
+ Some(n) => b.append_buffer(n.inner()),
+ None => b.append_n(s.len(), true),
+ }
+ }
+ NullBuffer::new(b.finish())
+ });
+
+ let mut column_concat_result = Vec::with_capacity(fields.len());
+ for i in 0..fields.len() {
+ let extracted_cols = structs
+ .iter()
+ .map(|s| s.column(i).as_ref())
+ .collect::<Vec<_>>();
+ column_concat_result.push(concat(&extracted_cols)?);
+ }
Review Comment:
```suggestion
let column_concat_result: Vec<_> = (0..fields.len()).map(|i| {
let extracted_cols = structs
.iter()
.map(|s| s.column(i).as_ref())
.collect::<Vec<_>>();
concat(&extracted_cols)?
})
```
--
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]