Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions datafusion/functions/src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,24 @@ impl StringArrayBuilder {
unsafe { self.offsets_buffer.push_unchecked(next_offset) };
}

/// Finalise the builder into a concrete [`StringArray`].
///
/// # Panics
///
/// This method can panic when:
///
/// - the provided `null_buffer` is not the same length as the `offsets_buffer`.
pub fn finish(self, null_buffer: Option<NullBuffer>) -> StringArray {
let row_count = self.offsets_buffer.len() / size_of::<i32>() - 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👨‍🍳 👌

if let Some(ref null_buffer) = null_buffer {
assert_eq!(
null_buffer.len(),
row_count,
"Null buffer and offsets buffer must be the same length"
);
}
let array_builder = ArrayDataBuilder::new(DataType::Utf8)
.len(self.offsets_buffer.len() / size_of::<i32>() - 1)
.len(row_count)
.add_buffer(self.offsets_buffer.into())
.add_buffer(self.value_buffer.into())
.nulls(null_buffer);
Expand Down Expand Up @@ -335,9 +350,24 @@ impl LargeStringArrayBuilder {
unsafe { self.offsets_buffer.push_unchecked(next_offset) };
}

/// Finalise the builder into a concrete [`LargeStringArray`].
///
/// # Panics
///
/// This method can panic when:
///
/// - the provided `null_buffer` is not the same length as the `offsets_buffer`.
pub fn finish(self, null_buffer: Option<NullBuffer>) -> LargeStringArray {
let row_count = self.offsets_buffer.len() / size_of::<i64>() - 1;
if let Some(ref null_buffer) = null_buffer {
assert_eq!(
null_buffer.len(),
row_count,
"Null buffer and offsets buffer must be the same length"
);
}
let array_builder = ArrayDataBuilder::new(DataType::LargeUtf8)
.len(self.offsets_buffer.len() / size_of::<i64>() - 1)
.len(row_count)
.add_buffer(self.offsets_buffer.into())
.add_buffer(self.value_buffer.into())
.nulls(null_buffer);
Expand Down
Loading