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

Method decode

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

Source from the content-addressed store, hash-verified

96 P::Native: ParseJsonNumber + NumCast,
97{
98 fn decode(&mut self, tape: &Tape<'_>, pos: &[u32]) -> Result<ArrayRef, ArrowError> {
99 let mut builder =
100 PrimitiveBuilder::<P>::with_capacity(pos.len()).with_data_type(self.data_type.clone());
101 let d = &self.data_type;
102
103 for p in pos {
104 let value = match tape.get(*p) {
105 TapeElement::Null => {
106 builder.append_null();
107 continue;
108 }
109 TapeElement::String(idx) => {
110 let s = tape.get_string(idx);
111 P::parse(s).ok_or_else(|| {
112 ArrowError::JsonError(format!("failed to parse \"{s}\" as {d}",))
113 })
114 }
115 TapeElement::Number(idx) => {
116 let s = tape.get_string(idx);
117 ParseJsonNumber::parse(s.as_bytes()).ok_or_else(|| {
118 ArrowError::JsonError(format!("failed to parse {s} as {d}",))
119 })
120 }
121 TapeElement::F32(v) => {
122 let v = f32::from_bits(v);
123 NumCast::from(v).ok_or_else(|| {
124 ArrowError::JsonError(format!("failed to parse {v} as {d}",))
125 })
126 }
127 TapeElement::I32(v) => NumCast::from(v)
128 .ok_or_else(|| ArrowError::JsonError(format!("failed to parse {v} as {d}",))),
129 TapeElement::F64(high) => match tape.get(p + 1) {
130 TapeElement::F32(low) => {
131 let v = f64::from_bits(((high as u64) << 32) | low as u64);
132 NumCast::from(v).ok_or_else(|| {
133 ArrowError::JsonError(format!("failed to parse {v} as {d}",))
134 })
135 }
136 _ => unreachable!(),
137 },
138 TapeElement::I64(high) => match tape.get(p + 1) {
139 TapeElement::I32(low) => {
140 let v = ((high as i64) << 32) | (low as u32) as i64;
141 NumCast::from(v).ok_or_else(|| {
142 ArrowError::JsonError(format!("failed to parse {v} as {d}",))
143 })
144 }
145 _ => unreachable!(),
146 },
147 _ => Err(tape.error(*p, "primitive")),
148 };
149
150 match value {
151 Ok(value) => builder.append_value(value),
152 Err(_) if self.ignore_type_conflicts => builder.append_null(),
153 Err(e) => return Err(e),
154 }
155 }

Callers

nothing calls this directly

Calls 11

get_stringMethod · 0.80
errorMethod · 0.80
parseFunction · 0.50
with_data_typeMethod · 0.45
lenMethod · 0.45
cloneMethod · 0.45
getMethod · 0.45
append_nullMethod · 0.45
as_bytesMethod · 0.45
append_valueMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected