Skip to content

Commit 7d56bb3

Browse files
ajaaymchingor13
authored andcommitted
---
yaml --- r: 12059 b: refs/heads/autosynth-dialogflow c: 2501613 h: refs/heads/master i: 12057: e86fc90 12055: 93f2f2b
1 parent af1fc1d commit 7d56bb3

5 files changed

Lines changed: 35 additions & 1 deletion

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ refs/heads/autosynth-bigtable: cd831a28dff2ba4d733608b871a1523a463e7380
130130
refs/heads/autosynth-bigtable-admin: 6379a2bc712f2736c83de0e009b4d26da4fa82ca
131131
refs/heads/autosynth-containeranalysis: 781fdb430a60f9a6491f116e31e4e10118157bdb
132132
refs/heads/autosynth-datastore: af1fb76aa3eee02fe6f31f8fa1c72a4f048d149b
133-
refs/heads/autosynth-dialogflow: 38ec041b6ddc84f7ea475df1618a1fe1a697acfe
133+
refs/heads/autosynth-dialogflow: 25016131f77f3038df3ca754fc784412bd1c162f
134134
refs/heads/autosynth-errorreporting: 518a442405c822492ed1c139e89e3e3d1804e29c
135135
refs/heads/autosynth-firestore: 450623a0568a156847a97f05d0ea5aeeeeaca698
136136
refs/heads/autosynth-iot: 2a21f544087dee8f5b5802779ff9e2a70c1acdca

branches/autosynth-dialogflow/google-cloud-clients/google-cloud-datastore/src/main/java/com/google/cloud/datastore/QueryResults.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,19 @@ public interface QueryResults<V> extends Iterator<V> {
5555
* }</pre>
5656
*/
5757
Cursor getCursorAfter();
58+
59+
/**
60+
* Returns the number of results skipped, typically because of an offset.
61+
*
62+
* <p>A simple use case to count entities:
63+
*
64+
* <pre>{@code
65+
* Query<Key> query = Query.newKeyQueryBuilder().setOffset(Integer.MAX_VALUE).build();
66+
* QueryResults<Key> result = datasore.datastore.run(query);
67+
* if (!result.hasNext()) {
68+
* int numberOfEntities = result.getSkippedResults();
69+
* }
70+
* }</pre>
71+
*/
72+
int getSkippedResults();
5873
}

branches/autosynth-dialogflow/google-cloud-clients/google-cloud-datastore/src/main/java/com/google/cloud/datastore/QueryResultsImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,9 @@ public Class<?> getResultClass() {
114114
public Cursor getCursorAfter() {
115115
return new Cursor(cursor);
116116
}
117+
118+
@Override
119+
public int getSkippedResults() {
120+
return runQueryResponsePb.getBatch().getSkippedResults();
121+
}
117122
}

branches/autosynth-dialogflow/google-cloud-clients/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,13 @@ public void testQueryPaginationWithLimit() throws DatastoreException {
633633
EasyMock.verify(rpcFactoryMock, rpcMock);
634634
}
635635

636+
@Test
637+
public void testRunKeyQueryWithOffset() {
638+
Query<Key> query = Query.newKeyQueryBuilder().setOffset(Integer.MAX_VALUE).build();
639+
int numberOfEntities = datastore.run(query).getSkippedResults();
640+
assertEquals(2, numberOfEntities);
641+
}
642+
636643
private List<RunQueryResponse> buildResponsesForQueryPaginationWithLimit() {
637644
Entity entity4 = Entity.newBuilder(KEY4).set("value", StringValue.of("value")).build();
638645
Entity entity5 = Entity.newBuilder(KEY5).set("value", "value").build();

branches/autosynth-dialogflow/google-cloud-clients/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,4 +851,11 @@ public Integer run(DatastoreReaderWriter transaction) {
851851
assertEquals(3, ((DatastoreException) expected.getCause()).getCode());
852852
}
853853
}
854+
855+
@Test
856+
public void testSkippedResults() {
857+
Query<Key> query = Query.newKeyQueryBuilder().setOffset(Integer.MAX_VALUE).build();
858+
int numberOfEntities = DATASTORE.run(query).getSkippedResults();
859+
assertEquals(2, numberOfEntities);
860+
}
854861
}

0 commit comments

Comments
 (0)