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

Method decode

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

Source from the content-addressed store, hash-verified

83
84impl ArrayDecoder for MapArrayDecoder {
85 fn decode(&mut self, tape: &Tape<'_>, pos: &[u32]) -> Result<ArrayRef, ArrowError> {
86 let mut offsets = BufferBuilder::<i32>::new(pos.len() + 1);
87 offsets.append(0);
88
89 let mut key_pos = Vec::with_capacity(pos.len());
90 let mut value_pos = Vec::with_capacity(pos.len());
91
92 let mut nulls = self.is_nullable.then(|| NullBufferBuilder::new(pos.len()));
93
94 for p in pos.iter().copied() {
95 let end_idx = match (tape.get(p), nulls.as_mut()) {
96 (TapeElement::StartObject(end_idx), None) => end_idx,
97 (TapeElement::StartObject(end_idx), Some(nulls)) => {
98 nulls.append_non_null();
99 end_idx
100 }
101 (TapeElement::Null, Some(nulls)) => {
102 nulls.append_null();
103 p + 1
104 }
105 (_, Some(nulls)) if self.ignore_type_conflicts => {
106 nulls.append_null();
107 p + 1
108 }
109 _ => return Err(tape.error(p, "{")),
110 };
111
112 let mut cur_idx = p + 1;
113 while cur_idx < end_idx {
114 let key = cur_idx;
115 let value = tape.next(key, "map key")?;
116 cur_idx = tape.next(value, "map value")?;
117
118 key_pos.push(key);
119 value_pos.push(value);
120 }
121
122 let offset = i32::from_usize(key_pos.len()).ok_or_else(|| {
123 ArrowError::JsonError("offset overflow decoding MapArray".to_string())
124 })?;
125 offsets.append(offset)
126 }
127
128 assert_eq!(key_pos.len(), value_pos.len());
129
130 let key_array = self.keys.decode(tape, &key_pos)?;
131 let value_array = self.values.decode(tape, &value_pos)?;
132
133 // SAFETY: fields/arrays match the schema, lengths are equal, no nulls
134 let entries = unsafe {
135 StructArray::new_unchecked_with_length(
136 self.key_value_fields.clone(),
137 vec![key_array, value_array],
138 None,
139 key_pos.len(),
140 )
141 };
142

Callers

nothing calls this directly

Calls 13

try_newFunction · 0.85
append_non_nullMethod · 0.80
errorMethod · 0.80
and_thenMethod · 0.80
lenMethod · 0.45
appendMethod · 0.45
iterMethod · 0.45
getMethod · 0.45
append_nullMethod · 0.45
nextMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected