jecsand838 commented on code in PR #8006: URL: https://github.com/apache/arrow-rs/pull/8006#discussion_r2251839467
########## arrow-avro/src/reader/mod.rs: ########## @@ -154,39 +165,175 @@ impl Decoder { /// /// Returns the number of bytes consumed. pub fn decode(&mut self, data: &[u8]) -> Result<usize, ArrowError> { + if self.writer_schema_store.is_some() + && data.len() >= SINGLE_OBJECT_MAGIC.len() + && !data.starts_with(&SINGLE_OBJECT_MAGIC) + { + return Err(ArrowError::ParseError( + "Expected single‑object encoding fingerprint prefix for first message \ + (writer_schema_store is set but active_fingerprint is None)" + .into(), + )); + } let mut total_consumed = 0usize; - while total_consumed < data.len() && self.decoded_rows < self.batch_size { - let consumed = self.record_decoder.decode(&data[total_consumed..], 1)?; - // A successful call to record_decoder.decode means one row was decoded. - // If `consumed` is 0 on a non-empty buffer, it implies a valid zero-byte record. - // We increment `decoded_rows` to mark progress and avoid an infinite loop. - // We add `consumed` (which can be 0) to `total_consumed`. - total_consumed += consumed; - self.decoded_rows += 1; + let hash_type = self.writer_schema_store.as_ref().map_or( + FingerprintAlgorithm::Rabin, + SchemaStore::fingerprint_algorithm, + ); + // The loop stops when the batch is full, a schema change is staged, + // or handle_prefix indicates we need more bytes (Some(0)). + while total_consumed < data.len() && self.remaining_capacity > 0 { + if let Some(n) = self.handle_prefix(&data[total_consumed..], hash_type)? { + // We either consumed a prefix (n > 0) and need a schema switch, or we need + // more bytes to make a decision. Either way, this decoding attempt is finished. Review Comment: @scovich I'm actually refactoring this code in my next PR to handle chunking partial records. Is it okay if we pick this up there? It will be ~300 LOC and exclusively focused on decoding. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org