@@ -61,7 +61,7 @@ func NewReader(opts ReaderOptions) *Reader {
6161// Read reads up to the next len(s) rows from r and stores them into s. It
6262// returns the number of rows read and any error encountered. At the end of the
6363// Dataset, Read returns 0, [io.EOF].
64- func (r * Reader ) Read (ctx context.Context , s []Row ) (n int , err error ) {
64+ func (r * Reader ) Read (ctx context.Context , s []Row ) (int , error ) {
6565 stats := StatsFromContext (ctx )
6666 stats .AddReadCalls (1 )
6767
@@ -105,16 +105,16 @@ func (r *Reader) Read(ctx context.Context, s []Row) (n int, err error) {
105105
106106 row , err := r .alignRow ()
107107 if err != nil {
108- return n , err
108+ return 0 , err
109109 } else if _ , err := r .inner .Seek (int64 (row ), io .SeekStart ); err != nil {
110- return n , fmt .Errorf ("failed to seek to row %d: %w" , row , err )
110+ return 0 , fmt .Errorf ("failed to seek to row %d: %w" , row , err )
111111 }
112112
113113 currentRange , ok := r .ranges .Range (row )
114114 if ! ok {
115115 // This should be unreachable; alignToRange already ensures that we're in a
116116 // range, or it returns io.EOF.
117- return n , fmt .Errorf ("failed to find range for row %d" , row )
117+ return 0 , fmt .Errorf ("failed to find range for row %d" , row )
118118 }
119119
120120 readSize := min (len (s ), int (currentRange .End - row + 1 ))
@@ -134,7 +134,7 @@ func (r *Reader) Read(ctx context.Context, s []Row) (n int, err error) {
134134 if len (r .opts .Predicates ) == 0 {
135135 count , err := r .inner .ReadColumns (ctx , r .primaryColumns (), s [:readSize ])
136136 if err != nil && ! errors .Is (err , io .EOF ) {
137- return n , err
137+ return count , err
138138 } else if count == 0 && errors .Is (err , io .EOF ) {
139139 return 0 , io .EOF
140140 }
@@ -151,7 +151,7 @@ func (r *Reader) Read(ctx context.Context, s []Row) (n int, err error) {
151151 } else {
152152 rowsRead , passCount , err = r .readAndFilterPrimaryColumns (ctx , readSize , s [:readSize ], stats )
153153 if err != nil {
154- return n , err
154+ return passCount , err
155155 }
156156 }
157157
@@ -169,9 +169,9 @@ func (r *Reader) Read(ctx context.Context, s []Row) (n int, err error) {
169169
170170 count , err := r .inner .Fill (ctx , secondary , s [:passCount ])
171171 if err != nil && ! errors .Is (err , io .EOF ) {
172- return n , err
172+ return count , err
173173 } else if count != passCount {
174- return n , fmt .Errorf ("failed to fill rows: expected %d, got %d" , n , count )
174+ return count , fmt .Errorf ("failed to fill rows: expected %d, got %d" , passCount , count )
175175 }
176176
177177 var totalBytesFilled int64
@@ -183,12 +183,10 @@ func (r *Reader) Read(ctx context.Context, s []Row) (n int, err error) {
183183 stats .AddSecondaryRowBytes (uint64 (totalBytesFilled ))
184184 }
185185
186- n += passCount
187-
188186 // We only advance r.row after we successfully read and filled rows. This
189187 // allows the caller to retry reading rows if a sporadic error occurs.
190188 r .row += int64 (rowsRead )
191- return n , nil
189+ return passCount , nil
192190}
193191
194192// readAndFilterPrimaryColumns reads the primary columns from the dataset
@@ -234,7 +232,7 @@ func (r *Reader) readAndFilterPrimaryColumns(ctx context.Context, readSize int,
234232 if err != nil && ! errors .Is (err , io .EOF ) {
235233 return rowsRead , 0 , err
236234 } else if count != readSize {
237- return rowsRead , 0 , fmt .Errorf ("failed to fill rows: expected %d, got %d" , len ( s ) , count )
235+ return rowsRead , 0 , fmt .Errorf ("failed to fill rows: expected %d, got %d" , readSize , count )
238236 }
239237 } else {
240238 count = readSize // required columns are already filled
0 commit comments