Skip to content

Queries that start at a cursor report that they start at the very beginning until you go to the first element #204

@gavin-haynes-grow

Description

@gavin-haynes-grow

A query result from a query that starts at a cursor will say getCursorAfter is actually the default cursor (Cursor{bytes=}) rather than the cursor it started with.

This creates complications for testing / resuming a result set that was never iterated.

The old Java 8 datastore SDK didn't have this issue.

Environment details

  1. Specify the API at the beginning of the title. For example, "BigQuery: ...").
    General, Core, and Other are also allowed as types
  2. OS type and version: any
  3. Java version: 8/11
  4. datastore version(s): current master (0.87.1)

Steps to reproduce

Start cloud_datastore_emulator on localhost:8081
Run code example

Code example

    import com.google.cloud.datastore.*;
    Datastore ds = DatastoreOptions.newBuilder().setProjectId("project").setHost("localhost:8081").build().getService();
    ds.put(Entity.newBuilder(Key.newBuilder("project", "Kind", "name-01").build()).build());
    ds.put(Entity.newBuilder(Key.newBuilder("project", "Kind", "name-02").build()).build());
    ds.put(Entity.newBuilder(Key.newBuilder("project", "Kind", "name-03").build()).build());
    QueryResults<Entity> run = ds.run(Query.newEntityQueryBuilder().setKind("Kind").build());
    run.next();
    Cursor cursor = run.getCursorAfter();
    QueryResults<Entity> run2 = ds.run(Query.newEntityQueryBuilder().setKind("Kind").setStartCursor(cursor).build());
    // expected:
    assert run2.getCursorAfter().equals(cursor);
    // actual: run2.getCursorAfter() is the default cursor until run2.next() is called

Metadata

Metadata

Assignees

Labels

api: datastoreIssues related to the googleapis/java-datastore API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions