viirya commented on code in PR #7987:
URL: https://github.com/apache/arrow-rs/pull/7987#discussion_r2232663787
##########
parquet-variant/src/builder.rs:
##########
@@ -1216,24 +1211,45 @@ impl<'a> ListBuilder<'a> {
/// Finalizes this list and appends it to its parent, which otherwise
remains unmodified.
pub fn finish(mut self) {
- let data_size = self.buffer.offset();
+ let buffer = self.parent_state.buffer();
+
+ let data_size = buffer.offset() - self.parent_value_offset_base;
+
let num_elements = self.offsets.len();
let is_large = num_elements > u8::MAX as usize;
let offset_size = int_size(data_size);
- // Get parent's buffer
- let parent_buffer = self.parent_state.buffer();
- let starting_offset = parent_buffer.offset();
+ let starting_offset = self.parent_value_offset_base;
+
+ let header_size = 1 + // header
+ if is_large { 4 } else { 1 } + // is_large
+ (self.offsets.len() + 1) * offset_size as usize; // offsets and
data size
+ // Calculated header size becomes a hint; being wrong only risks extra
allocations.
+ // Make sure to reserve enough capacity to handle the extra bytes
we'll truncate.
Review Comment:
When `header_size` will be incorrect?
--
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]