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

Function extract_decimal_as_string

nodedb-strict/src/arrow_extract.rs:266–298  ·  view source on GitHub ↗

Decimal → String representation for Arrow (DataFusion handles decimal as strings or Decimal128 — we use string for lossless representation).

(
    decoder: &TupleDecoder,
    tuples: &[&[u8]],
    col_idx: usize,
    n: usize,
)

Source from the content-addressed store, hash-verified

264/// Decimal → String representation for Arrow (DataFusion handles decimal as strings
265/// or Decimal128 — we use string for lossless representation).
266fn extract_decimal_as_string(
267 decoder: &TupleDecoder,
268 tuples: &[&[u8]],
269 col_idx: usize,
270 n: usize,
271) -> Result<ArrayRef, StrictError> {
272 let (null_buf, null_count) = build_null_buffer(decoder, tuples, col_idx)?;
273 let mut strs: Vec<Option<String>> = Vec::with_capacity(n);
274
275 for tuple in tuples {
276 if let Some(raw) = decoder.extract_fixed_raw(tuple, col_idx)? {
277 let mut bytes = [0u8; 16];
278 bytes.copy_from_slice(&raw[..16]);
279 let dec = rust_decimal::Decimal::deserialize(bytes);
280 strs.push(Some(dec.to_string()));
281 } else {
282 strs.push(None);
283 }
284 }
285
286 let array = StringArray::from(strs);
287 if null_count > 0 {
288 let data = array
289 .into_data()
290 .into_builder()
291 .null_bit_buffer(Some(null_buf.into_inner().into_inner()))
292 .build()
293 .expect("arrow array builder lengths are consistent");
294 Ok(Arc::new(StringArray::from(data)))
295 } else {
296 Ok(Arc::new(array))
297 }
298}
299
300fn extract_uuid(
301 decoder: &TupleDecoder,

Callers 1

extract_column_to_arrowFunction · 0.85

Calls 7

build_null_bufferFunction · 0.85
deserializeFunction · 0.85
extract_fixed_rawMethod · 0.80
to_stringMethod · 0.80
pushMethod · 0.45
expectMethod · 0.45
buildMethod · 0.45

Tested by

no test coverage detected