Skip to content

Commit ebf4029

Browse files
committed
cleaned up skip_blocks method.
1 parent 9423bf1 commit ebf4029

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

arrow-avro/src/reader/record.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -756,9 +756,8 @@ enum NegativeBlockBehavior {
756756

757757
#[inline]
758758
fn skip_blocks(
759-
buf: &mut AvroCursor<'_>,
760-
mut skip_item: impl FnMut(&mut AvroCursor<'_>) -> Result<(), ArrowError>,
761-
_skip_negative_block_by_size: bool,
759+
buf: &mut AvroCursor,
760+
mut skip_item: impl FnMut(&mut AvroCursor) -> Result<(), ArrowError>,
762761
) -> Result<usize, ArrowError> {
763762
process_blockwise(
764763
buf,
@@ -777,16 +776,22 @@ fn read_blocks(
777776

778777
#[inline]
779778
fn process_blockwise(
780-
buf: &mut AvroCursor<'_>,
781-
mut on_item: impl FnMut(&mut AvroCursor<'_>) -> Result<(), ArrowError>,
779+
buf: &mut AvroCursor,
780+
mut on_item: impl FnMut(&mut AvroCursor) -> Result<(), ArrowError>,
782781
negative_behavior: NegativeBlockBehavior,
783782
) -> Result<usize, ArrowError> {
784783
let mut total = 0usize;
785784
loop {
785+
// Read the block count
786+
// positive = that many items
787+
// negative = that many items + read block size
788+
// See: https://avro.apache.org/docs/1.11.1/specification/#maps
786789
let block_count = buf.get_long()?;
787790
match block_count.cmp(&0) {
788791
Ordering::Equal => break,
789792
Ordering::Less => {
793+
// If block_count is negative, read the absolute value of count,
794+
// then read the block size as a long and discard
790795
let count = (-block_count) as usize;
791796
// A negative count is followed by a long of the size in bytes
792797
let size_in_bytes = buf.get_long()? as usize;
@@ -805,6 +810,7 @@ fn process_blockwise(
805810
total += count;
806811
}
807812
Ordering::Greater => {
813+
// If block_count is positive, decode that many items
808814
let count = block_count as usize;
809815
for _ in 0..count {
810816
on_item(buf)?;
@@ -978,18 +984,14 @@ impl Skipper {
978984
Ok(())
979985
}
980986
Self::List(item) => {
981-
skip_blocks(buf, |c| item.skip(c), true)?;
987+
skip_blocks(buf, |c| item.skip(c))?;
982988
Ok(())
983989
}
984990
Self::Map(value) => {
985-
skip_blocks(
986-
buf,
987-
|c| {
988-
c.get_bytes()?; // key
989-
value.skip(c)
990-
},
991-
true,
992-
)?;
991+
skip_blocks(buf, |c| {
992+
c.get_bytes()?; // key
993+
value.skip(c)
994+
})?;
993995
Ok(())
994996
}
995997
Self::Struct(fields) => {

0 commit comments

Comments
 (0)