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

Method decode

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

Source from the content-addressed store, hash-verified

45
46impl ArrayDecoder for StringViewArrayDecoder {
47 fn decode(&mut self, tape: &Tape<'_>, pos: &[u32]) -> Result<ArrayRef, ArrowError> {
48 let coerce = self.coerce_primitive;
49 let mut data_capacity = 0;
50 for &p in pos {
51 // note that StringView is different that StringArray in that only
52 // "long" strings (longer than 12 bytes) are stored in the buffer.
53 // "short" strings are inlined into a fixed length structure.
54 match tape.get(p) {
55 TapeElement::String(idx) => {
56 let s = tape.get_string(idx);
57 // Only increase capacity if the string length is greater than 12 bytes
58 if s.len() > 12 {
59 data_capacity += s.len();
60 }
61 }
62 TapeElement::Null => {
63 // Do not increase capacity for null values
64 }
65 // For booleans, do not increase capacity (both "true" and "false" are less than
66 // 12 bytes)
67 TapeElement::True if coerce => {}
68 TapeElement::False if coerce => {}
69 // For Number, use the same strategy as for strings
70 TapeElement::Number(idx) if coerce => {
71 let s = tape.get_string(idx);
72 if s.len() > 12 {
73 data_capacity += s.len();
74 }
75 }
76 // For I64, only add capacity if the absolute value is greater than 999,999,999,999
77 // (the largest number that can fit in 12 bytes)
78 TapeElement::I64(_) if coerce => {
79 match tape.get(p + 1) {
80 TapeElement::I32(_) => {
81 let high = match tape.get(p) {
82 TapeElement::I64(h) => h,
83 _ => unreachable!(),
84 };
85 let low = match tape.get(p + 1) {
86 TapeElement::I32(l) => l,
87 _ => unreachable!(),
88 };
89 let val = ((high as i64) << 32) | (low as u32) as i64;
90 if val.abs() > 999_999_999_999 {
91 // Only allocate capacity based on the string representation if the number is large
92 data_capacity += val.to_string().len();
93 }
94 }
95 _ => unreachable!(),
96 }
97 }
98 // For I32, do not increase capacity (the longest string representation is <= 12 bytes)
99 TapeElement::I32(_) if coerce => {}
100 // For F32 and F64, keep the existing estimate
101 TapeElement::F32(_) if coerce => {
102 data_capacity += 10;
103 }
104 TapeElement::F64(_) if coerce => {

Callers

nothing calls this directly

Calls 9

get_stringMethod · 0.80
absMethod · 0.80
errorMethod · 0.80
getMethod · 0.45
lenMethod · 0.45
append_valueMethod · 0.45
append_nullMethod · 0.45
clearMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected