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

Method decode

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

Source from the content-addressed store, hash-verified

54 Tz: TimeZone + Send,
55{
56 fn decode(&mut self, tape: &Tape<'_>, pos: &[u32]) -> Result<ArrayRef, ArrowError> {
57 let mut builder =
58 PrimitiveBuilder::<P>::with_capacity(pos.len()).with_data_type(self.data_type.clone());
59 for p in pos {
60 let value = match tape.get(*p) {
61 TapeElement::Null => {
62 builder.append_null();
63 continue;
64 }
65 TapeElement::String(idx) => {
66 let s = tape.get_string(idx);
67 let date = string_to_datetime(&self.timezone, s).map_err(|e| {
68 ArrowError::JsonError(format!(
69 "failed to parse \"{s}\" as {}: {}",
70 self.data_type, e
71 ))
72 });
73
74 date.and_then(|date| match P::UNIT {
75 TimeUnit::Second => Ok(date.timestamp()),
76 TimeUnit::Millisecond => Ok(date.timestamp_millis()),
77 TimeUnit::Microsecond => Ok(date.timestamp_micros()),
78 TimeUnit::Nanosecond => date.timestamp_nanos_opt().ok_or_else(|| {
79 ArrowError::ParseError(format!(
80 "{} would overflow 64-bit signed nanoseconds",
81 date.to_rfc3339(),
82 ))
83 }),
84 })
85 }
86 TapeElement::Number(idx) => {
87 let s = tape.get_string(idx);
88 let b = s.as_bytes();
89 lexical_core::parse::<i64>(b)
90 .or_else(|_| lexical_core::parse::<f64>(b).map(|x| x as i64))
91 .map_err(|_| {
92 ArrowError::JsonError(format!(
93 "failed to parse {s} as {}",
94 self.data_type
95 ))
96 })
97 }
98 TapeElement::I32(v) => Ok(v as i64),
99 TapeElement::I64(high) => match tape.get(p + 1) {
100 TapeElement::I32(low) => Ok(((high as i64) << 32) | (low as u32) as i64),
101 _ => unreachable!(),
102 },
103 _ => Err(tape.error(*p, "primitive")),
104 };
105
106 match value {
107 Ok(value) => builder.append_value(value),
108 Err(_) if self.ignore_type_conflicts => builder.append_null(),
109 Err(e) => return Err(e),
110 }
111 }
112
113 Ok(Arc::new(builder.finish()))

Callers

nothing calls this directly

Calls 13

string_to_datetimeFunction · 0.85
get_stringMethod · 0.80
and_thenMethod · 0.80
timestampMethod · 0.80
errorMethod · 0.80
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

Tested by

no test coverage detected