简体   繁体   中英

Datastore query with limit

I'm using the RemoteAPI (Java) to go through a large dataset, ~90K entities, and perform some data migration.

int CHUNK_SIZE = 500;
int LIMIT = 900; 

QueryResultList<Entity> result = ds.prepare(entityQuery)
.asQueryResultList(
    FetchOptions.Builder
    .withPrefetchSize(CHUNK_SIZE)
    .limit(LIMIT)
    .chunkSize(CHUNK_SIZE)
).startCursor(cursor);

With the query LIMIT set to 900 the result.size() is the entire dataset, ~90K, instead of 900 . If I try a lower LIMIT , say 300 , the result size is the expected one ( 300 ).

What am I missing here? From the documentation I couldn't figure out why it produces the behaviour I'm describing here.

Based on these examples ( http://www.programcreek.com/java-api-examples/index.php?api=com.google.appengine.api.datastore.QueryResultList )

I think that you should use .withLimit(LIMIT) instead of .limit(LIMIT) within the .asQueryResultList options

So I would restructure your code as follows:

FetchOptions options = FetchOptions.Builder
    .withLimit(LIMIT)
    .withPrefetchSize(CHUNK_SIZE)
    .chunkSize(CHUNK_SIZE);

QueryResultList<Entity> result = ds.prepare(entityQuery)
    .asQueryResultList(options);

Then get cursor

result.getCursor();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM