@@ -756,9 +756,8 @@ enum NegativeBlockBehavior {
756
756
757
757
#[ inline]
758
758
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 > ,
762
761
) -> Result < usize , ArrowError > {
763
762
process_blockwise (
764
763
buf,
@@ -777,16 +776,22 @@ fn read_blocks(
777
776
778
777
#[ inline]
779
778
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 > ,
782
781
negative_behavior : NegativeBlockBehavior ,
783
782
) -> Result < usize , ArrowError > {
784
783
let mut total = 0usize ;
785
784
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
786
789
let block_count = buf. get_long ( ) ?;
787
790
match block_count. cmp ( & 0 ) {
788
791
Ordering :: Equal => break ,
789
792
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
790
795
let count = ( -block_count) as usize ;
791
796
// A negative count is followed by a long of the size in bytes
792
797
let size_in_bytes = buf. get_long ( ) ? as usize ;
@@ -805,6 +810,7 @@ fn process_blockwise(
805
810
total += count;
806
811
}
807
812
Ordering :: Greater => {
813
+ // If block_count is positive, decode that many items
808
814
let count = block_count as usize ;
809
815
for _ in 0 ..count {
810
816
on_item ( buf) ?;
@@ -978,18 +984,14 @@ impl Skipper {
978
984
Ok ( ( ) )
979
985
}
980
986
Self :: List ( item) => {
981
- skip_blocks ( buf, |c| item. skip ( c) , true ) ?;
987
+ skip_blocks ( buf, |c| item. skip ( c) ) ?;
982
988
Ok ( ( ) )
983
989
}
984
990
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
+ } ) ?;
993
995
Ok ( ( ) )
994
996
}
995
997
Self :: Struct ( fields) => {
0 commit comments