@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.datastore.v1.QueryResultBatch)) { return super.equals(obj); } com.google.datastore.v1.QueryResultBatch other = (com.google.datastore.v1.QueryResultBatch) obj; boolean result = true; result = result && (getSkippedResults() == other.getSkippedResults()); result = result && getSkippedCursor().equals(other.getSkippedCursor()); result = result && entityResultType_ == other.entityResultType_; result = result && getEntityResultsList().equals(other.getEntityResultsList()); result = result && getEndCursor().equals(other.getEndCursor()); result = result && moreResults_ == other.moreResults_; result = result && (getSnapshotVersion() == other.getSnapshotVersion()); result = result && unknownFields.equals(other.unknownFields); return result; }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); hash = (37 * hash) + SKIPPED_RESULTS_FIELD_NUMBER; hash = (53 * hash) + getSkippedResults(); hash = (37 * hash) + SKIPPED_CURSOR_FIELD_NUMBER; hash = (53 * hash) + getSkippedCursor().hashCode(); hash = (37 * hash) + ENTITY_RESULT_TYPE_FIELD_NUMBER; hash = (53 * hash) + entityResultType_; if (getEntityResultsCount() > 0) { hash = (37 * hash) + ENTITY_RESULTS_FIELD_NUMBER; hash = (53 * hash) + getEntityResultsList().hashCode(); } hash = (37 * hash) + END_CURSOR_FIELD_NUMBER; hash = (53 * hash) + getEndCursor().hashCode(); hash = (37 * hash) + MORE_RESULTS_FIELD_NUMBER; hash = (53 * hash) + moreResults_; hash = (37 * hash) + SNAPSHOT_VERSION_FIELD_NUMBER; hash = (53 * hash) + com.google.protobuf.Internal.hashLong(getSnapshotVersion()); hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
private void sendRequest() { com.google.datastore.v1.RunQueryRequest.Builder requestPb = com.google.datastore.v1.RunQueryRequest.newBuilder(); if (readOptionsPb != null) { requestPb.setReadOptions(readOptionsPb); } requestPb.setPartitionId(partitionIdPb); query.populatePb(requestPb); runQueryResponsePb = datastore.runQuery(requestPb.build()); mostRecentQueryPb = runQueryResponsePb.getQuery(); if (mostRecentQueryPb == null) { mostRecentQueryPb = requestPb.getQuery(); } lastBatch = runQueryResponsePb.getBatch().getMoreResults() != MoreResultsType.NOT_FINISHED; entityResultPbIter = runQueryResponsePb.getBatch().getEntityResultsList().iterator(); actualResultType = ResultType.fromPb(runQueryResponsePb.getBatch().getEntityResultType()); if (Objects.equals(queryResultType, ResultType.PROJECTION_ENTITY)) { // projection entity can represent all type of results actualResultType = ResultType.PROJECTION_ENTITY; } Preconditions.checkState( queryResultType.isAssignableFrom(actualResultType), "Unexpected result type " + actualResultType + " vs " + queryResultType); }
.setMoreResults(QueryResultBatch.MoreResultsType.NOT_FINISHED) .clearEntityResults() .addAllEntityResults(queryResultBatchPb.getEntityResultsList().subList(0, 1)) .setEndCursor(queryResultBatchPb.getEntityResultsList().get(0).getCursor()) .build(); responses.add(RunQueryResponse.newBuilder().setBatch(queryResultBatchPb1).build()); .setMoreResults(QueryResultBatch.MoreResultsType.NOT_FINISHED) .clearEntityResults() .addAllEntityResults(queryResultBatchPb.getEntityResultsList().subList(1, 3)) .setEndCursor(queryResultBatchPb.getEntityResultsList().get(2).getCursor()) .build(); responses.add(RunQueryResponse.newBuilder().setBatch(queryResultBatchPb2).build()); .setMoreResults(QueryResultBatch.MoreResultsType.NO_MORE_RESULTS) .clearEntityResults() .addAllEntityResults(queryResultBatchPb.getEntityResultsList().subList(3, 5)) .setEndCursor(queryResultBatchPb.getEntityResultsList().get(4).getCursor()) .build(); responses.add(RunQueryResponse.newBuilder().setBatch(queryResultBatchPb3).build());
.setMoreResults(QueryResultBatch.MoreResultsType.NOT_FINISHED) .clearEntityResults() .addAllEntityResults(queryResultBatchPb.getEntityResultsList().subList(0, 1)) .setEndCursor(ByteString.copyFromUtf8("a")) .build(); .setMoreResults(QueryResultBatch.MoreResultsType.MORE_RESULTS_AFTER_LIMIT) .clearEntityResults() .addAllEntityResults(queryResultBatchPb.getEntityResultsList().subList(1, 2)) .setEndCursor( ByteString.copyFrom(new byte[] {(byte) 0x80})) // test invalid UTF-8 string .setMoreResults(QueryResultBatch.MoreResultsType.MORE_RESULTS_AFTER_LIMIT) .clearEntityResults() .addAllEntityResults(queryResultBatchPb.getEntityResultsList().subList(2, 4)) .setEndCursor(ByteString.copyFromUtf8("b")) .build(); .setMoreResults(QueryResultBatch.MoreResultsType.NO_MORE_RESULTS) .clearEntityResults() .addAllEntityResults(queryResultBatchPb.getEntityResultsList().subList(4, 5)) .setEndCursor(ByteString.copyFromUtf8("c")) .build();
static QueryResult build(final com.google.datastore.v1.RunQueryResponse response) { final com.google.datastore.v1.QueryResultBatch batch = response.getBatch(); return new QueryResult(ImmutableList.copyOf( response.getBatch().getEntityResultsList().stream() .map(entity -> Entity.builder(entity.getEntity()).build()) .collect(Collectors.toList())), batch.getEndCursor()); }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.datastore.v1.QueryResultBatch)) { return super.equals(obj); } com.google.datastore.v1.QueryResultBatch other = (com.google.datastore.v1.QueryResultBatch) obj; boolean result = true; result = result && (getSkippedResults() == other.getSkippedResults()); result = result && getSkippedCursor().equals(other.getSkippedCursor()); result = result && entityResultType_ == other.entityResultType_; result = result && getEntityResultsList().equals(other.getEntityResultsList()); result = result && getEndCursor().equals(other.getEndCursor()); result = result && moreResults_ == other.moreResults_; result = result && (getSnapshotVersion() == other.getSnapshotVersion()); result = result && unknownFields.equals(other.unknownFields); return result; }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); hash = (37 * hash) + SKIPPED_RESULTS_FIELD_NUMBER; hash = (53 * hash) + getSkippedResults(); hash = (37 * hash) + SKIPPED_CURSOR_FIELD_NUMBER; hash = (53 * hash) + getSkippedCursor().hashCode(); hash = (37 * hash) + ENTITY_RESULT_TYPE_FIELD_NUMBER; hash = (53 * hash) + entityResultType_; if (getEntityResultsCount() > 0) { hash = (37 * hash) + ENTITY_RESULTS_FIELD_NUMBER; hash = (53 * hash) + getEntityResultsList().hashCode(); } hash = (37 * hash) + END_CURSOR_FIELD_NUMBER; hash = (53 * hash) + getEndCursor().hashCode(); hash = (37 * hash) + MORE_RESULTS_FIELD_NUMBER; hash = (53 * hash) + moreResults_; hash = (37 * hash) + SNAPSHOT_VERSION_FIELD_NUMBER; hash = (53 * hash) + com.google.protobuf.Internal.hashLong(getSnapshotVersion()); hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptorForType().hashCode(); hash = (37 * hash) + SKIPPED_RESULTS_FIELD_NUMBER; hash = (53 * hash) + getSkippedResults(); hash = (37 * hash) + SKIPPED_CURSOR_FIELD_NUMBER; hash = (53 * hash) + getSkippedCursor().hashCode(); hash = (37 * hash) + ENTITY_RESULT_TYPE_FIELD_NUMBER; hash = (53 * hash) + entityResultType_; if (getEntityResultsCount() > 0) { hash = (37 * hash) + ENTITY_RESULTS_FIELD_NUMBER; hash = (53 * hash) + getEntityResultsList().hashCode(); } hash = (37 * hash) + END_CURSOR_FIELD_NUMBER; hash = (53 * hash) + getEndCursor().hashCode(); hash = (37 * hash) + MORE_RESULTS_FIELD_NUMBER; hash = (53 * hash) + moreResults_; hash = (37 * hash) + SNAPSHOT_VERSION_FIELD_NUMBER; hash = (53 * hash) + com.google.protobuf.Internal.hashLong( getSnapshotVersion()); hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.datastore.v1.QueryResultBatch)) { return super.equals(obj); } com.google.datastore.v1.QueryResultBatch other = (com.google.datastore.v1.QueryResultBatch) obj; boolean result = true; result = result && (getSkippedResults() == other.getSkippedResults()); result = result && getSkippedCursor() .equals(other.getSkippedCursor()); result = result && entityResultType_ == other.entityResultType_; result = result && getEntityResultsList() .equals(other.getEntityResultsList()); result = result && getEndCursor() .equals(other.getEndCursor()); result = result && moreResults_ == other.moreResults_; result = result && (getSnapshotVersion() == other.getSnapshotVersion()); return result; }
/** * Run a query on the datastore. * * @return The entities returned by the query. * @throws DatastoreException on error */ private List<Entity> runQuery(Query query) throws DatastoreException { RunQueryRequest.Builder request = RunQueryRequest.newBuilder(); request.setQuery(query); RunQueryResponse response = datastore.runQuery(request.build()); if (response.getBatch().getMoreResults() == QueryResultBatch.MoreResultsType.NOT_FINISHED) { System.err.println("WARNING: partial results\n"); } List<EntityResult> results = response.getBatch().getEntityResultsList(); List<Entity> entities = new ArrayList<Entity>(results.size()); for (EntityResult result : results) { entities.add(result.getEntity()); } return entities; } }
private void sendRequest() { com.google.datastore.v1.RunQueryRequest.Builder requestPb = com.google.datastore.v1.RunQueryRequest.newBuilder(); if (readOptionsPb != null) { requestPb.setReadOptions(readOptionsPb); } requestPb.setPartitionId(partitionIdPb); query.populatePb(requestPb); runQueryResponsePb = datastore.runQuery(requestPb.build()); mostRecentQueryPb = runQueryResponsePb.getQuery(); if (mostRecentQueryPb == null) { mostRecentQueryPb = requestPb.getQuery(); } lastBatch = runQueryResponsePb.getBatch().getMoreResults() != MoreResultsType.NOT_FINISHED; entityResultPbIter = runQueryResponsePb.getBatch().getEntityResultsList().iterator(); actualResultType = ResultType.fromPb(runQueryResponsePb.getBatch().getEntityResultType()); if (Objects.equals(queryResultType, ResultType.PROJECTION_ENTITY)) { // projection entity can represent all type of results actualResultType = ResultType.PROJECTION_ENTITY; } Preconditions.checkState( queryResultType.isAssignableFrom(actualResultType), "Unexpected result type " + actualResultType + " vs " + queryResultType); }
.build(); batch = datastore.runQuery(scatterRequest).getBatch(); for (EntityResult result : batch.getEntityResultsList()) { keySplits.add(result.getEntity().getKey());
.build(); batch = datastore.runQuery(scatterRequest).getBatch(); for (EntityResult result : batch.getEntityResultsList()) { keySplits.add(result.getEntity().getKey());
private Iterator<EntityResult> getIteratorAndMoveCursor() throws DatastoreException { Query.Builder query = this.query.toBuilder(); query.setLimit(Int32Value.newBuilder().setValue(QUERY_BATCH_LIMIT)); if (currentBatch != null && !currentBatch.getEndCursor().isEmpty()) { query.setStartCursor(currentBatch.getEndCursor()); } RunQueryRequest request = makeRequest(query.build(), namespace); RunQueryResponse response = datastore.runQuery(request); currentBatch = response.getBatch(); int numFetch = currentBatch.getEntityResultsCount(); // All indications from the API are that there are/may be more results. moreResults = ((numFetch == QUERY_BATCH_LIMIT) || (currentBatch.getMoreResults() == NOT_FINISHED)); // May receive a batch of 0 results if the number of records is a multiple // of the request limit. if (numFetch == 0) { return null; } return currentBatch.getEntityResultsList().iterator(); } }
for (EntityResult entityResult : currentBatch.getEntityResultsList()) { context.output(entityResult.getEntity());