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,
)
| 264 | /// Decimal → String representation for Arrow (DataFusion handles decimal as strings |
| 265 | /// or Decimal128 — we use string for lossless representation). |
| 266 | fn 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 | |
| 300 | fn extract_uuid( |
| 301 | decoder: &TupleDecoder, |
no test coverage detected