MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / extract_string

Function extract_string

nodedb-strict/src/arrow_extract.rs:201–231  ·  view source on GitHub ↗
(
    decoder: &TupleDecoder,
    tuples: &[&[u8]],
    col_idx: usize,
    n: usize,
)

Source from the content-addressed store, hash-verified

199}
200
201fn extract_string(
202 decoder: &TupleDecoder,
203 tuples: &[&[u8]],
204 col_idx: usize,
205 n: usize,
206) -> Result<ArrayRef, StrictError> {
207 let (null_buf, null_count) = build_null_buffer(decoder, tuples, col_idx)?;
208 let mut strs: Vec<Option<&str>> = Vec::with_capacity(n);
209
210 for tuple in tuples {
211 if let Some(raw) = decoder.extract_variable_raw(tuple, col_idx)? {
212 strs.push(Some(std::str::from_utf8(raw).unwrap_or("")));
213 } else {
214 strs.push(None);
215 }
216 }
217
218 let array = StringArray::from(strs);
219 // Reapply our null buffer in case of nulls not captured by Option.
220 if null_count > 0 {
221 let data = array
222 .into_data()
223 .into_builder()
224 .null_bit_buffer(Some(null_buf.into_inner().into_inner()))
225 .build()
226 .expect("arrow array builder lengths are consistent");
227 Ok(Arc::new(StringArray::from(data)))
228 } else {
229 Ok(Arc::new(array))
230 }
231}
232
233fn extract_binary(
234 decoder: &TupleDecoder,

Callers 1

extract_column_to_arrowFunction · 0.70

Calls 5

build_null_bufferFunction · 0.85
extract_variable_rawMethod · 0.80
pushMethod · 0.45
expectMethod · 0.45
buildMethod · 0.45

Tested by

no test coverage detected