Skip to content

Commit 9079bbd

Browse files
authored
Fix concat_elements_utf8view capacity initialization. (#18003)
## Which issue does this PR close? - Relates to #17857 (See #17857 (comment)) ## Rationale for this change The capacity calculation replaced with `left.len()` (assuming `left.len()` and `right.len()` are the same). As the `with_capacity` refers to the length of the views (or strings), not to the length of the bytes ## Are these changes tested? The function is already covered by tests. ## Are there any user-facing changes? No
1 parent e323357 commit 9079bbd

File tree

1 file changed

+8
-6
lines changed
  • datafusion/physical-expr/src/expressions/binary

1 file changed

+8
-6
lines changed

datafusion/physical-expr/src/expressions/binary/kernels.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,14 @@ pub fn concat_elements_utf8view(
145145
left: &StringViewArray,
146146
right: &StringViewArray,
147147
) -> std::result::Result<StringViewArray, ArrowError> {
148-
let capacity = left
149-
.data_buffers()
150-
.iter()
151-
.zip(right.data_buffers().iter())
152-
.map(|(b1, b2)| b1.len() + b2.len())
153-
.sum();
148+
if left.len() != right.len() {
149+
return Err(ArrowError::ComputeError(format!(
150+
"Arrays must have the same length: {} != {}",
151+
left.len(),
152+
right.len()
153+
)));
154+
}
155+
let capacity = left.len();
154156
let mut result = StringViewBuilder::with_capacity(capacity);
155157

156158
// Avoid reallocations by writing to a reused buffer (note we

0 commit comments

Comments
 (0)