MCPcopy Create free account
hub / github.com/apache/arrow-rs / consume_batch

Method consume_batch

parquet/src/arrow/array_reader/fixed_len_byte_array.rs:179–248  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

177 }
178
179 fn consume_batch(&mut self) -> Result<ArrayRef> {
180 let record_data = self.record_reader.consume_record_data();
181
182 let array_data = ArrayDataBuilder::new(ArrowType::FixedSizeBinary(self.byte_length as i32))
183 .len(self.record_reader.num_values())
184 .add_buffer(Buffer::from_vec(record_data.buffer))
185 .null_bit_buffer(self.record_reader.consume_bitmap_buffer());
186
187 let binary = FixedSizeBinaryArray::from(unsafe { array_data.build_unchecked() });
188
189 // TODO: An improvement might be to do this conversion on read
190 // Note the conversions below apply to all elements regardless of null slots as the
191 // conversion lambdas are all infallible. This improves performance by avoiding a branch in
192 // the inner loop (see docs for `PrimitiveArray::from_unary`).
193 let array: ArrayRef = match &self.data_type {
194 ArrowType::Decimal32(p, s) => {
195 let f = |b: &[u8]| i32::from_be_bytes(sign_extend_be(b));
196 Arc::new(Decimal32Array::from_unary(&binary, f).with_precision_and_scale(*p, *s)?)
197 as ArrayRef
198 }
199 ArrowType::Decimal64(p, s) => {
200 let f = |b: &[u8]| i64::from_be_bytes(sign_extend_be(b));
201 Arc::new(Decimal64Array::from_unary(&binary, f).with_precision_and_scale(*p, *s)?)
202 as ArrayRef
203 }
204 ArrowType::Decimal128(p, s) => {
205 let f = |b: &[u8]| i128::from_be_bytes(sign_extend_be(b));
206 Arc::new(Decimal128Array::from_unary(&binary, f).with_precision_and_scale(*p, *s)?)
207 as ArrayRef
208 }
209 ArrowType::Decimal256(p, s) => {
210 let f = |b: &[u8]| i256::from_be_bytes(sign_extend_be(b));
211 Arc::new(Decimal256Array::from_unary(&binary, f).with_precision_and_scale(*p, *s)?)
212 as ArrayRef
213 }
214 ArrowType::Interval(unit) => {
215 // An interval is stored as 3x 32-bit unsigned integers storing months, days,
216 // and milliseconds
217 match unit {
218 IntervalUnit::YearMonth => {
219 let f = |b: &[u8]| i32::from_le_bytes(b[0..4].try_into().unwrap());
220 Arc::new(IntervalYearMonthArray::from_unary(&binary, f)) as ArrayRef
221 }
222 IntervalUnit::DayTime => {
223 let f = |b: &[u8]| {
224 IntervalDayTime::new(
225 i32::from_le_bytes(b[4..8].try_into().unwrap()),
226 i32::from_le_bytes(b[8..12].try_into().unwrap()),
227 )
228 };
229 Arc::new(IntervalDayTimeArray::from_unary(&binary, f)) as ArrayRef
230 }
231 IntervalUnit::MonthDayNano => {
232 return Err(nyi_err!("MonthDayNano intervals not supported"));
233 }
234 }
235 }
236 ArrowType::Float16 => {

Callers

nothing calls this directly

Calls 13

FixedSizeBinaryClass · 0.85
sign_extend_beFunction · 0.85
consume_record_dataMethod · 0.80
add_bufferMethod · 0.80
consume_bitmap_bufferMethod · 0.80
consume_def_levelsMethod · 0.80
consume_rep_levelsMethod · 0.80
null_bit_bufferMethod · 0.45
lenMethod · 0.45
num_valuesMethod · 0.45
build_uncheckedMethod · 0.45

Tested by

no test coverage detected