systemboot
systemboot

Reputation: 862

Querying Riak data in one fetch

I am using the Riak java client to perform a date range query in the 2i (Secondary Index). This query returns a list of keys, which I submit again to Riak to fetch the entries. Is there a way to execute these two queries in one go, so that I can save time on server round trip. Here is my code snippet:

        Bucket bucket = client.fetchBucket(bucketName).execute();

        FetchIndex<Number> indexQuery = bucket.fetchIndex(intIndex)
                .from(fromInMillis).to(toInMillis).maxResults(maxRows);
        if (continuationToken != null) {
            indexQuery.withContinuation(continuationToken);
        }

        StreamingOperation<IndexEntry> op = indexQuery.executeStreaming();
        List<IndexEntry> indexEntries = op.getAll();

        if(indexEntries.size() == 0){
            return;
        }

        if (op.hasContinuation()) {
            response.put("continuationToken", op.getContinuation());
        }



        String[] keys = new String[indexEntries.size()];
        for (int i = 0; i < keys.length; i++) {
            keys[i] = indexEntries.get(i).getObjectKey();
        }

        List<MultiFetchFuture<IRiakObject>> values = bucket
                .multiFetch(keys).execute();

Upvotes: 1

Views: 428

Answers (2)

Rohit More
Rohit More

Reputation: 23

You can try to use multiFetch.

What multifetch does is for given set of keys, it tries to parallelize individual fetch operations.

For further information check out the documentation: http://basho.github.io/riak-java-client/2.0.7/ Class MultiFetch

Upvotes: 0

Brian Roach
Brian Roach

Reputation: 76908

No, there's not. That's simply just how Riak works.

A 2i query only returns a list of object keys (or, a list of 2i key / object key pairs).

Upvotes: 1

Related Questions