This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 1a169cd638 Fix `MutableBuffer::clear` (#9622)
1a169cd638 is described below
commit 1a169cd638aa4b72ccb4961e37e5014a66308718
Author: Alexander Rafferty <[email protected]>
AuthorDate: Wed Apr 1 06:27:16 2026 +1100
Fix `MutableBuffer::clear` (#9622)
# Which issue does this PR close?
- closes https://github.com/apache/arrow-rs/pull/9593
# Rationale for this change
In a previous PR (#9593), I change instances of `truncate(0)` to
`clear()`. However, this breaks the test `test_truncate_with_pool` at
`arrow-buffer/src/buffer/mutable.rs:1357`, due to an inconsistency
between the implementation of `truncate` and `clear`. This PR fixes that
test.
# What changes are included in this PR?
This PR copies a section of code related to the `pool` feature present
in `truncate` but absent in `clear`, fixing the failing unit test.
# Are these changes tested?
Yes.
# Are there any user-facing changes?
No.
---
arrow-buffer/src/buffer/mutable.rs | 10 ++++++++--
arrow-json/src/reader/value_iter.rs | 2 +-
parquet/tests/geospatial.rs | 4 ++--
3 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/arrow-buffer/src/buffer/mutable.rs
b/arrow-buffer/src/buffer/mutable.rs
index 9fc8605061..07ef965cb0 100644
--- a/arrow-buffer/src/buffer/mutable.rs
+++ b/arrow-buffer/src/buffer/mutable.rs
@@ -450,7 +450,13 @@ impl MutableBuffer {
/// Clear all existing data from this buffer.
pub fn clear(&mut self) {
- self.len = 0
+ self.len = 0;
+ #[cfg(feature = "pool")]
+ {
+ if let Some(reservation) =
self.reservation.lock().unwrap().as_mut() {
+ reservation.resize(self.len);
+ }
+ }
}
/// Returns the data stored in this buffer as a slice.
@@ -1371,7 +1377,7 @@ mod tests {
assert_eq!(pool.used(), 40);
// Truncate to zero
- buffer.truncate(0);
+ buffer.clear();
assert_eq!(buffer.len(), 0);
assert_eq!(pool.used(), 0);
}
diff --git a/arrow-json/src/reader/value_iter.rs
b/arrow-json/src/reader/value_iter.rs
index f70b893f52..ebaba695ad 100644
--- a/arrow-json/src/reader/value_iter.rs
+++ b/arrow-json/src/reader/value_iter.rs
@@ -73,7 +73,7 @@ impl<R: BufRead> Iterator for ValueIter<R> {
}
loop {
- self.line_buf.truncate(0);
+ self.line_buf.clear();
match self.reader.read_line(&mut self.line_buf) {
Ok(0) => {
// read_line returns 0 when stream reached EOF
diff --git a/parquet/tests/geospatial.rs b/parquet/tests/geospatial.rs
index 4f449df920..fcc93661ed 100644
--- a/parquet/tests/geospatial.rs
+++ b/parquet/tests/geospatial.rs
@@ -380,8 +380,8 @@ mod test {
for i in 0..reader.num_row_groups() {
let row_group = reader.get_row_group(i).unwrap();
- values.truncate(0);
- def_levels.truncate(0);
+ values.clear();
+ def_levels.clear();
let mut row_group_out = writer.next_row_group().unwrap();