Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update BulkWriter.delete() to return sentinel value #250

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ public ApiFuture<WriteResult> delete(@Nonnull DocumentReference documentReferenc
*
* @param documentReference The DocumentReference to delete.
* @param precondition Precondition to enforce for this delete.
* @return An ApiFuture containing the result of the delete. Contains an error if the delete
* fails.
* @return An ApiFuture containing a sentinel value (Timestamp(0)) for the delete operation.
* Contains an error if the delete fails.
*/
@Nonnull
public ApiFuture<WriteResult> delete(
Expand All @@ -167,7 +167,8 @@ public ApiFuture<WriteResult> delete(
*
* @param documentReference A reference to the document to be set.
* @param fields A map of the fields and values for the document.
* @return An ApiFuture containing the result of the write. Contains an error if the write fails.
* @return An ApiFuture containing a sentinel value (Timestamp(0)) for the delete operation.
* Contains an error if the delete fails.
*/
@Nonnull
public ApiFuture<WriteResult> set(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,12 +697,21 @@ public List<BatchWriteResult> apply(BatchWriteResponse batchWriteResponse) {
for (int i = 0; i < writeResults.size(); ++i) {
com.google.firestore.v1.WriteResult writeResult = writeResults.get(i);
com.google.rpc.Status status = statuses.get(i);
result.add(
new BatchWriteResult(
writeResult.hasUpdateTime()
? Timestamp.fromProto(writeResult.getUpdateTime())
: null,
Status.fromCodeValue(status.getCode())));
Timestamp updateTime = null;

// Since delete operations currently do not have write times, use a
// sentinel Timestamp value.
// TODO(b/158502664): Use actual delete timestamp.
boolean isSuccessfulDelete =
!writeResult.hasUpdateTime()
&& Status.fromCodeValue(status.getCode()) == Status.OK;
Timestamp DELETE_TIMESTAMP_SENTINEL = Timestamp.ofTimeSecondsAndNanos(0, 0);
if (isSuccessfulDelete) {
updateTime = DELETE_TIMESTAMP_SENTINEL;
} else if (writeResult.hasUpdateTime()) {
updateTime = Timestamp.fromProto(writeResult.getUpdateTime());
}
result.add(new BatchWriteResult(updateTime, Status.fromCodeValue(status.getCode())));
}

return result;
Expand Down