|
3 | 3 |
|
4 | 4 | use std::any::Any; |
5 | 5 |
|
| 6 | +use vortex_buffer::BufferAllocatorRef; |
6 | 7 | use vortex_buffer::BufferMut; |
7 | 8 | use vortex_error::VortexExpect; |
8 | 9 | use vortex_error::VortexResult; |
@@ -103,13 +104,31 @@ impl DecimalBuilder { |
103 | 104 | capacity: usize, |
104 | 105 | decimal: DecimalDType, |
105 | 106 | nullability: Nullability, |
| 107 | + ) -> Self { |
| 108 | + Self::with_capacity_in::<T>( |
| 109 | + capacity, |
| 110 | + decimal, |
| 111 | + nullability, |
| 112 | + BufferAllocatorRef::statically_allocated(), |
| 113 | + ) |
| 114 | + } |
| 115 | + |
| 116 | + /// Creates a decimal builder with the given capacity and allocator. |
| 117 | + pub fn with_capacity_in<T: NativeDecimalType>( |
| 118 | + capacity: usize, |
| 119 | + decimal: DecimalDType, |
| 120 | + nullability: Nullability, |
| 121 | + allocator: BufferAllocatorRef, |
106 | 122 | ) -> Self { |
107 | 123 | Self { |
108 | 124 | dtype: DType::Decimal(decimal, nullability), |
109 | 125 | values: match_each_decimal_value_type!(T::DECIMAL_TYPE, |D| { |
110 | | - DecimalBuffer::from(BufferMut::<D>::with_capacity(capacity)) |
| 126 | + DecimalBuffer::from(BufferMut::<D>::with_capacity_in( |
| 127 | + capacity, |
| 128 | + allocator.clone(), |
| 129 | + )) |
111 | 130 | }), |
112 | | - nulls: LazyBitBufferBuilder::new(capacity), |
| 131 | + nulls: LazyBitBufferBuilder::new_in(capacity, allocator), |
113 | 132 | } |
114 | 133 | } |
115 | 134 |
|
@@ -153,7 +172,7 @@ impl DecimalBuilder { |
153 | 172 |
|
154 | 173 | let decimal_dtype = *self.decimal_dtype(); |
155 | 174 |
|
156 | | - delegate_fn!(std::mem::take(&mut self.values), |T, values| { |
| 175 | + delegate_fn!(self.values.take(), |T, values| { |
157 | 176 | DecimalArray::new::<T>(values.freeze(), decimal_dtype, validity) |
158 | 177 | }) |
159 | 178 | } |
@@ -228,6 +247,13 @@ impl ArrayBuilder for DecimalBuilder { |
228 | 247 | } |
229 | 248 |
|
230 | 249 | impl DecimalBuffer { |
| 250 | + fn take(&mut self) -> Self { |
| 251 | + delegate_fn!(self, |T, buffer| { |
| 252 | + let allocator = buffer.allocator(); |
| 253 | + DecimalBuffer::from(std::mem::replace(buffer, allocator.with_capacity(0))) |
| 254 | + }) |
| 255 | + } |
| 256 | + |
231 | 257 | fn push<V: NativeDecimalType>(&mut self, value: V) { |
232 | 258 | delegate_fn!(self, |T, buffer| { |
233 | 259 | buffer.push( |
@@ -291,12 +317,6 @@ impl_from_buffer!(i64, I64); |
291 | 317 | impl_from_buffer!(i128, I128); |
292 | 318 | impl_from_buffer!(i256, I256); |
293 | 319 |
|
294 | | -impl Default for DecimalBuffer { |
295 | | - fn default() -> Self { |
296 | | - Self::I8(BufferMut::<i8>::empty()) |
297 | | - } |
298 | | -} |
299 | | - |
300 | 320 | #[cfg(test)] |
301 | 321 | mod tests { |
302 | 322 | use crate::VortexSessionExecute; |
|
0 commit comments