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

Method decode

arrow-json/src/reader/list_array.rs:67–133  ·  view source on GitHub ↗
(&mut self, tape: &Tape<'_>, pos: &[u32])

Source from the content-addressed store, hash-verified

65
66impl<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 };

Callers

nothing calls this directly

Calls 12

try_newFunction · 0.85
append_non_nullMethod · 0.80
errorMethod · 0.80
and_thenMethod · 0.80
lenMethod · 0.45
pushMethod · 0.45
getMethod · 0.45
append_nullMethod · 0.45
nextMethod · 0.45
finishMethod · 0.45
cloneMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected