Finalize the builder into a concrete [`StringArray`]. # Errors Returns an error when: - the provided `null_buffer` is not the same length as the `offsets_buffer`.
(self, null_buffer: Option<NullBuffer>)
| 134 | /// |
| 135 | /// - the provided `null_buffer` is not the same length as the `offsets_buffer`. |
| 136 | pub fn finish(self, null_buffer: Option<NullBuffer>) -> Result<StringArray> { |
| 137 | let row_count = self.offsets_buffer.len() / size_of::<i32>() - 1; |
| 138 | if let Some(ref null_buffer) = null_buffer |
| 139 | && null_buffer.len() != row_count |
| 140 | { |
| 141 | return internal_err!( |
| 142 | "Null buffer and offsets buffer must be the same length" |
| 143 | ); |
| 144 | } |
| 145 | let array_builder = ArrayDataBuilder::new(DataType::Utf8) |
| 146 | .len(row_count) |
| 147 | .add_buffer(self.offsets_buffer.into()) |
| 148 | .add_buffer(self.value_buffer.into()) |
| 149 | .nulls(null_buffer); |
| 150 | if self.tainted { |
| 151 | // Raw binary arrays with possible invalid utf-8 were used, |
| 152 | // so let ArrayDataBuilder perform validation |
| 153 | let array_data = array_builder.build()?; |
| 154 | Ok(StringArray::from(array_data)) |
| 155 | } else { |
| 156 | // SAFETY: all data that was appended was valid UTF8 and the values |
| 157 | // and offsets were created correctly |
| 158 | let array_data = unsafe { array_builder.build_unchecked() }; |
| 159 | Ok(StringArray::from(array_data)) |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | /// Builder used by `concat`/`concat_ws` to assemble a [`StringViewArray`] one |