(&mut self, tape: &Tape<'_>, pos: &[u32])
| 65 | |
| 66 | impl<O: OffsetSizeTrait, const IS_VIEW: bool> ArrayDecoder for ListLikeArrayDecoder<O, IS_VIEW> { |
| 67 | fn decode(&mut self, tape: &Tape<'_>, pos: &[u32]) -> Result<ArrayRef, ArrowError> { |
| 68 | let mut child_pos = Vec::with_capacity(pos.len()); |
| 69 | let mut offsets = Vec::with_capacity(pos.len() + 1); |
| 70 | offsets.push(O::from_usize(0).unwrap()); |
| 71 | |
| 72 | let mut nulls = self.is_nullable.then(|| NullBufferBuilder::new(pos.len())); |
| 73 | |
| 74 | for p in pos { |
| 75 | let end_idx = match (tape.get(*p), nulls.as_mut()) { |
| 76 | (TapeElement::StartList(end_idx), None) => end_idx, |
| 77 | (TapeElement::StartList(end_idx), Some(nulls)) => { |
| 78 | nulls.append_non_null(); |
| 79 | end_idx |
| 80 | } |
| 81 | (TapeElement::Null, Some(nulls)) => { |
| 82 | nulls.append_null(); |
| 83 | *p + 1 |
| 84 | } |
| 85 | (_, Some(nulls)) if self.ignore_type_conflicts => { |
| 86 | nulls.append_null(); |
| 87 | *p + 1 |
| 88 | } |
| 89 | _ => return Err(tape.error(*p, "[")), |
| 90 | }; |
| 91 | |
| 92 | let mut cur_idx = *p + 1; |
| 93 | while cur_idx < end_idx { |
| 94 | child_pos.push(cur_idx); |
| 95 | |
| 96 | // Advance to next field |
| 97 | cur_idx = tape.next(cur_idx, "list value")?; |
| 98 | } |
| 99 | |
| 100 | let offset = O::from_usize(child_pos.len()).ok_or_else(|| { |
| 101 | ArrowError::JsonError(format!("offset overflow decoding {}ListArray", O::PREFIX)) |
| 102 | })?; |
| 103 | offsets.push(offset); |
| 104 | } |
| 105 | |
| 106 | let values = self.decoder.decode(tape, &child_pos)?; |
| 107 | let nulls = nulls.as_mut().and_then(|x| x.finish()); |
| 108 | |
| 109 | if IS_VIEW { |
| 110 | let mut sizes = Vec::with_capacity(offsets.len() - 1); |
| 111 | for i in 1..offsets.len() { |
| 112 | sizes.push(offsets[i] - offsets[i - 1]); |
| 113 | } |
| 114 | offsets.pop(); |
| 115 | // SAFETY: offsets and sizes are constructed correctly from the tape |
| 116 | let array = unsafe { |
| 117 | GenericListViewArray::<O>::new_unchecked( |
| 118 | self.field.clone(), |
| 119 | ScalarBuffer::from(offsets), |
| 120 | ScalarBuffer::from(sizes), |
| 121 | values, |
| 122 | nulls, |
| 123 | ) |
| 124 | }; |
nothing calls this directly
no test coverage detected