(
&self,
reader: Box<dyn FileRead>,
file_size: u64,
read_fields: &[DataField],
_predicates: Option<&FilePredicates>,
batch_size: Option<usize>,
| 42 | #[async_trait] |
| 43 | impl FormatFileReader for AvroFormatReader { |
| 44 | async fn read_batch_stream( |
| 45 | &self, |
| 46 | reader: Box<dyn FileRead>, |
| 47 | file_size: u64, |
| 48 | read_fields: &[DataField], |
| 49 | _predicates: Option<&FilePredicates>, |
| 50 | batch_size: Option<usize>, |
| 51 | row_selection: Option<Vec<RowRange>>, |
| 52 | ) -> crate::Result<ArrowRecordBatchStream> { |
| 53 | // NOTE: Avro OCF requires sequential reading, so we load the entire file into memory. |
| 54 | // This is fine for typical Paimon data files but may be problematic for very large files. |
| 55 | let file_bytes = reader.read(0..file_size).await?; |
| 56 | |
| 57 | let read_fields = read_fields.to_vec(); |
| 58 | let target_schema = build_target_arrow_schema(&read_fields)?; |
| 59 | let batch_size = batch_size.unwrap_or(DEFAULT_BATCH_SIZE); |
| 60 | |
| 61 | // Collect Avro records directly as apache_avro::Value, avoiding intermediate conversion. |
| 62 | let all_records: Vec<Value> = Reader::new(&file_bytes[..]) |
| 63 | .map_err(|e| Error::UnexpectedError { |
| 64 | message: format!("Failed to open Avro file: {e}"), |
| 65 | source: Some(Box::new(e)), |
| 66 | })? |
| 67 | .collect::<std::result::Result<Vec<Value>, _>>() |
| 68 | .map_err(|e| Error::UnexpectedError { |
| 69 | message: format!("Failed to deserialize Avro record: {e}"), |
| 70 | source: Some(Box::new(e)), |
| 71 | })?; |
| 72 | |
| 73 | // Apply row selection filtering. |
| 74 | let records: Vec<Value> = match row_selection { |
| 75 | Some(ref ranges) => { |
| 76 | let total_rows = all_records.len(); |
| 77 | let mask = ranges_to_mask(total_rows, ranges); |
| 78 | all_records |
| 79 | .into_iter() |
| 80 | .enumerate() |
| 81 | .filter(|(i, _)| mask[*i]) |
| 82 | .map(|(_, r)| r) |
| 83 | .collect() |
| 84 | } |
| 85 | None => all_records, |
| 86 | }; |
| 87 | |
| 88 | Ok(try_stream! { |
| 89 | for chunk in records.chunks(batch_size) { |
| 90 | let batch = records_to_batch(chunk, &read_fields, &target_schema)?; |
| 91 | yield batch; |
| 92 | } |
| 93 | } |
| 94 | .boxed()) |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | // --------------------------------------------------------------------------- |
nothing calls this directly
no test coverage detected