-
Notifications
You must be signed in to change notification settings - Fork 553
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
QueryResults.next? keeps returning true forever under emulator #793
Comments
BTW, in the emulator log I don't see any new requests when I'm calling |
I found out that |
|
And, as a separate related issue, if understand semantics of |
I'll look at this over the weekend. That's frustrating that the live service and emulator behave differently. Thanks for letting us know @timanovsky! |
@blowmage if you want to reproduce, it is very basic ancestry query, no any other query params (no limit etc). Result set is expected to be 1 entry.
|
You don't need ancestry query. Minimal code to reproduce the problem: require 'gcloud/datastore'
dataset = Gcloud.datastore()
key = Gcloud::Datastore::Key.new("EntryA", "keyA")
entity = Gcloud::Datastore::Entity.new
entity.key = key
dataset.save(entity)
query = Gcloud::Datastore::Query.new
query.kind("EntryA")
r = dataset.run(query)
r.next?
r.more_results
r.next.next? |
I've looked into this over the weekend and this appears to be a bug in the beta emulator. I didn't get the Normally, when a query has no more results it will return the value Working around this is tricky. We don't want to introduce any bugs to gcloud-ruby in an effort to fix this for the emulator. There is a legitimate use for One option is to use the query = datastore.query "EntryA"
datastore.run(query).all(request_limit: 10) do |entry|
puts entry
end
I don't see them in the log output either, but those requests are happening.
Those are two different things. Specifying the limit in the query will limit the number of results returned in the initial request. But if you paginate those results it will request more and more results. My understanding is that To stop at a limit, you can specify a limit in the query. But, there are no guarantees that the server will return the limit. It may return less than the limit. It all depends on what is happening on the server. Alternatively, you can use ruby's Enumerable to take the number of results you are looking for. This will load all the records until the server indicates there are no more results, or the specified number of results is taken, whichever comes first. query = datastore.query "EntryA"
first_25 = datastore.run(query).all.take(25) Also, you can combine this with the query = datastore.query "EntryA"
first_25 = datastore.run(query).all(request_limit: 10).take(25) |
@pcostell Can you confirm that this is a bug in the emulator? If so, how do we file an issue for it? |
This is a known issue with the emulator, I'll find the public issue you can Something to note:
This is not the issue here but for posterity: in order to determine if you |
Importantly there are two features exposed through the Our desired behavior for RunQuery is a streaming API. If a user asks for a limit of N, we will give them a stream of up to N entities. We can then add some helpers on top of that to convert the stream to a list. Since we are still moving everything over to gRPC (which will allow this), we have a batching API which can be used to simulate a streaming API:
Separately, Cloud Datastore offers a paging feature, which provides the user a cursor they can use to get extra pages. This has an extra feature which is best effort end condition tracking ( |
I couldn't find an existing issue (I believe it lives in one of the other gcloud libraries). Here is one for the emulator: googleapis/google-cloud-datastore#130 |
Okay, so interestingly, with the change it is no longer possible to paginating with query = dataset.query("EntryA").limit(3)
dataset.run(query).all.count #=> always 3, even if there are thousands of results This is the desired behavior, right? |
The use of |
Agreed, it doesn't mesh with query = dataset.query("Task")
dataset.run(query).all.take(250) # paginate as many times as it takes to get 250 results |
Change what check is made to paginate. Requested by the Datastore team. [closes googleapis#793]
Hello, I've finally got some time to upgrade from 0.8.2. I'm running into the problem running a query under emulator. Basically subject says it all. Query returns 1 entry, but
next?==true
,.next
return 0 entries, but againnext?==true
and so on. With real cloud API it works fine returning one record. This btw results in.all
hanging.The emulator I downloaded from documentation page link: https://storage.googleapis.com/gcd/tools/cloud-datastore-emulator-1.1.1.zip
The text was updated successfully, but these errors were encountered: