Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docstore/awsdynamodb: Fix Query for cases where the underlying query to AWS returns an empty set, but there's still more data #3408

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 18 additions & 12 deletions docstore/awsdynamodb/query.go
Expand Up @@ -471,30 +471,36 @@

func (it *documentIterator) Next(ctx context.Context, doc driver.Document) error {
// Skip the first 'n' documents where 'n' is the offset.
if it.offset > 0 && it.count < it.offset {
it.curr++
it.count++
return it.Next(ctx, doc)
for it.count < it.offset {
if err := it.next(ctx, doc, false); err != nil {
return err

Check warning on line 476 in docstore/awsdynamodb/query.go

View check run for this annotation

Codecov / codecov/patch

docstore/awsdynamodb/query.go#L476

Added line #L476 was not covered by tests
}
}
return it.next(ctx, doc, true)
}

func (it *documentIterator) next(ctx context.Context, doc driver.Document, decode bool) error {
// Only start counting towards the limit after the offset has been reached.
if it.limit > 0 && it.count >= it.offset+it.limit || it.curr >= len(it.items) && it.last == nil {
if it.limit > 0 && it.count >= it.offset+it.limit {
return io.EOF
}
if it.curr >= len(it.items) {
// it.items can be empty after a call to it.qr.run, but unless it.last is nil there may be more items.
for it.curr >= len(it.items) {
// Make a new query request at the end of this page.
if it.last == nil {
return io.EOF
}
var err error
it.items, it.last, it.asFunc, err = it.qr.run(ctx, it.last)
if err != nil {
return err
}
it.curr = 0
}
// If there are no more items, return EOF.
if len(it.items) == 0 {
return io.EOF
}
if err := decodeDoc(&dyn.AttributeValue{M: it.items[it.curr]}, doc); err != nil {
return err
if decode {
if err := decodeDoc(&dyn.AttributeValue{M: it.items[it.curr]}, doc); err != nil {
return err

Check warning on line 502 in docstore/awsdynamodb/query.go

View check run for this annotation

Codecov / codecov/patch

docstore/awsdynamodb/query.go#L502

Added line #L502 was not covered by tests
}
}
it.curr++
it.count++
Expand Down