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

Function decode

arrow-row/src/run.rs:87–154  ·  view source on GitHub ↗

Decodes a RunEndEncodedArray from `rows` with the provided `options` # Safety `rows` must contain valid data for the provided `converter`

(
    converter: &RowConverter,
    rows: &mut [&[u8]],
    field: &SortField,
    validate_utf8: bool,
)

Source from the content-addressed store, hash-verified

85///
86/// `rows` must contain valid data for the provided `converter`
87pub unsafe fn decode<R: RunEndIndexType>(
88 converter: &RowConverter,
89 rows: &mut [&[u8]],
90 field: &SortField,
91 validate_utf8: bool,
92) -> Result<RunArray<R>, ArrowError> {
93 if rows.is_empty() {
94 let values = unsafe { converter.convert_raw(&mut [], validate_utf8) }?;
95 let run_ends_array = PrimitiveArray::<R>::try_new(ScalarBuffer::from(vec![]), None)?;
96 return RunArray::<R>::try_new(&run_ends_array, &values[0]);
97 }
98
99 // Decode each row's REE data and collect the decoded values
100 let mut decoded_values = Vec::new();
101 let mut run_ends = Vec::new();
102 let mut unique_row_indices = Vec::new();
103
104 // Process each row to extract its REE data (following decode_binary pattern)
105 let mut decoded_data = Vec::new();
106 for (idx, row) in rows.iter_mut().enumerate() {
107 decoded_data.clear();
108 // Extract the decoded value data from this row
109 let consumed = variable::decode_blocks(row, field.options, |block| {
110 decoded_data.extend_from_slice(block);
111 });
112
113 // Handle bit inversion for descending sort (following decode_binary pattern)
114 if field.options.descending {
115 decoded_data.iter_mut().for_each(|b| *b = !*b);
116 }
117
118 // Update the row to point past the consumed REE data
119 *row = &row[consumed..];
120
121 // Check if this decoded value is the same as the previous one to identify runs
122 let is_new_run =
123 idx == 0 || decoded_data != decoded_values[*unique_row_indices.last().unwrap()];
124
125 if is_new_run {
126 // This is a new unique value - end the previous run if any
127 if idx > 0 {
128 run_ends.push(R::Native::usize_as(idx));
129 }
130 unique_row_indices.push(decoded_values.len());
131 let capacity = decoded_data.capacity();
132 decoded_values.push(std::mem::replace(
133 &mut decoded_data,
134 Vec::with_capacity(capacity),
135 ));
136 }
137 }
138 // Add the final run end
139 run_ends.push(R::Native::usize_as(rows.len()));
140
141 // Convert the unique decoded values using the row converter
142 let mut unique_rows: Vec<&[u8]> = decoded_values.iter().map(|v| v.as_slice()).collect();
143 let values = if unique_rows.is_empty() {
144 unsafe { converter.convert_raw(&mut [], validate_utf8) }?

Callers 15

decodeMethod · 0.70
decode_fixedFunction · 0.70
cancel_flight_infoMethod · 0.50
renew_flight_endpointMethod · 0.50
unpackMethod · 0.50
get_flight_infoMethod · 0.50
do_getMethod · 0.50
do_putMethod · 0.50
do_actionMethod · 0.50
execute_updateMethod · 0.50
execute_ingestMethod · 0.50
prepareMethod · 0.50

Calls 13

try_newFunction · 0.85
decode_blocksFunction · 0.85
convert_rawMethod · 0.80
extend_from_sliceMethod · 0.80
collectMethod · 0.80
is_emptyMethod · 0.45
clearMethod · 0.45
lastMethod · 0.45
pushMethod · 0.45
lenMethod · 0.45
capacityMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected