(
buf: Vec<u8>,
skip_validation: bool,
)
| 2435 | } |
| 2436 | |
| 2437 | fn read_ipc_with_decoder_inner( |
| 2438 | buf: Vec<u8>, |
| 2439 | skip_validation: bool, |
| 2440 | ) -> Result<RecordBatch, ArrowError> { |
| 2441 | let buffer = Buffer::from_vec(buf); |
| 2442 | let trailer_start = buffer.len() - 10; |
| 2443 | let footer_len = read_footer_length(buffer[trailer_start..].try_into().unwrap())?; |
| 2444 | let footer = root_as_footer(&buffer[trailer_start - footer_len..trailer_start]) |
| 2445 | .map_err(|e| ArrowError::InvalidArgumentError(format!("Invalid footer: {e}")))?; |
| 2446 | |
| 2447 | let schema = fb_to_schema(footer.schema().unwrap()); |
| 2448 | |
| 2449 | let mut decoder = unsafe { |
| 2450 | FileDecoder::new(Arc::new(schema), footer.version()) |
| 2451 | .with_skip_validation(skip_validation) |
| 2452 | }; |
| 2453 | // Read dictionaries |
| 2454 | for block in footer.dictionaries().iter().flatten() { |
| 2455 | let block_len = block.bodyLength() as usize + block.metaDataLength() as usize; |
| 2456 | let data = buffer.slice_with_length(block.offset() as _, block_len); |
| 2457 | decoder.read_dictionary(block, &data)? |
| 2458 | } |
| 2459 | |
| 2460 | // Read record batch |
| 2461 | let batches = footer.recordBatches().unwrap(); |
| 2462 | assert_eq!(batches.len(), 1); // Only wrote a single batch |
| 2463 | |
| 2464 | let block = batches.get(0); |
| 2465 | let block_len = block.bodyLength() as usize + block.metaDataLength() as usize; |
| 2466 | let data = buffer.slice_with_length(block.offset() as _, block_len); |
| 2467 | Ok(decoder.read_record_batch(block, &data)?.unwrap()) |
| 2468 | } |
| 2469 | |
| 2470 | /// Write the record batch to an in-memory buffer in IPC Stream format |
| 2471 | fn write_stream(rb: &RecordBatch) -> Vec<u8> { |
no test coverage detected