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: replace usages of transform proto with update_transform #213

Merged
merged 9 commits into from May 19, 2020

Conversation

thebrianchen
Copy link

Porting from node. Also added additional system test port as well.

Conformance tests are passing locally against the custom [branch] of modified conformance tests (https://github.com/googleapis/java-conformance-tests/tree/bump/2020-05-12_141750) in googleapis/java-conformance-test. According to @BenWhitehead, once this PR is LGTM'd, we will:

  1. Merge the conformance test PR into conformance-tests.
  2. Create new release of java-conformance-tests.
  3. Update java-firestore to the new release.
  4. Rebuild this PR and ensure everything passes before merging.

@thebrianchen thebrianchen self-assigned this May 13, 2020
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label May 13, 2020
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably merge this into a feature branch and only merge to master once this PR and the conformance test update is ready. We need the updated conformance tests to validate these changes thoroughly.

@@ -535,13 +527,11 @@ public boolean allowTransform() {
Mutation mutation = addMutation();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can probably remove the Mutation type and replace it with the Proto type. What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. I remember you did this for node and the code became much cleaner. Removed Mutation and renamed mutation related variables to write.


if (mutation.document != null) {
request.addWrites(mutation.document);
mutation.document.setCurrentDocument(mutation.precondition);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use the Write proto directly instead of Mutation, we should be able to get rid of this line.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using the write proto directly now, but I can't see how to remove this line. Don't we always need to check if the precondition exists before setting it onto the write?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, sorry - I thought this was in "commit()". Looks good.

responseIterator.next();
}

mutationIterator.next();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be simpler now if we just replace it with a for loop.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried it with a for loop, intellij recommended I use while loop since the local variable in the for loop was redundant.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should iterator over writeResults and drop mutationIterator altogether.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After changing it to iterate through writeResults, intellij recommended that it be converted to an "enhanced for loop".

@@ -196,7 +200,10 @@ public void arrayUnionWithPojo() throws ExecutionException, InterruptedException
doc.update("array", FieldValue.arrayUnion(SINGLE_FIELD_OBJECT)).get();

CommitRequest expectedRequest =
commit(transform(UPDATE_PRECONDITION, "array", arrayUnion(SINGLE_FIELD_VALUE)));
commit(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of exposing an overload to commit?

 public static CommitRequest commit(Write write, List<FieldTransform> transform) {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. Got rid of writeWithTransform.

Copy link
Author

@thebrianchen thebrianchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably merge this into a feature branch and only merge to master once this PR and the conformance test update is ready. We need the updated conformance tests to validate these changes thoroughly.

I detailed the merge steps in the PR description. I talked to Ben about this, and he said that he will help facilitate merging this PR in once the new conformance tests have been added. I've run these against the updated conformance tests locally and they are passing. Merging this into a separate branch might make things easier for him though.

responseIterator.next();
}

mutationIterator.next();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried it with a for loop, intellij recommended I use while loop since the local variable in the for loop was redundant.

@@ -196,7 +200,10 @@ public void arrayUnionWithPojo() throws ExecutionException, InterruptedException
doc.update("array", FieldValue.arrayUnion(SINGLE_FIELD_OBJECT)).get();

CommitRequest expectedRequest =
commit(transform(UPDATE_PRECONDITION, "array", arrayUnion(SINGLE_FIELD_VALUE)));
commit(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. Got rid of writeWithTransform.


if (mutation.document != null) {
request.addWrites(mutation.document);
mutation.document.setCurrentDocument(mutation.precondition);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using the write proto directly now, but I can't see how to remove this line. Don't we always need to check if the precondition exists before setting it onto the write?

@@ -535,13 +527,11 @@ public boolean allowTransform() {
Mutation mutation = addMutation();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. I remember you did this for node and the code became much cleaner. Removed Mutation and renamed mutation related variables to write.

Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one final nit (the while loop)

Thanks for forcing me to read the PR description.

} else if (hasDocumentData || documentTransform.isEmpty()) {
mutation.document = documentSnapshot.toPb();
mutation.document.setUpdateMask(documentMask.toPb());
verifyNotCommitted();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels out of place now. Move to top of method?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.


if (mutation.document != null) {
request.addWrites(mutation.document);
mutation.document.setCurrentDocument(mutation.precondition);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, sorry - I thought this was in "commit()". Looks good.

responseIterator.next();
}

mutationIterator.next();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should iterator over writeResults and drop mutationIterator altogether.

@schmidt-sebastian schmidt-sebastian removed their assignment May 14, 2020
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

return (T) this;
}

/** Adds a new mutation to the batch. */
private Mutation addMutation() {
/** Adds a new write to the batch. */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect javadoc now that the mutation has been removed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the javadoc since the method is pretty straightforward now.

@BenWhitehead
Copy link
Collaborator

The release of the conformance tests is available. @thebrianchen Can you bump the dependency like is done in this PR: #218 that should allow your builds to be green.

@codecov
Copy link

codecov bot commented May 15, 2020

Codecov Report

Merging #213 into master will decrease coverage by 0.15%.
The diff coverage is 97.43%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #213      +/-   ##
============================================
- Coverage     73.09%   72.94%   -0.16%     
+ Complexity     1031     1015      -16     
============================================
  Files            63       63              
  Lines          5434     5407      -27     
  Branches        627      617      -10     
============================================
- Hits           3972     3944      -28     
- Misses         1264     1266       +2     
+ Partials        198      197       -1     
Impacted Files Coverage Δ Complexity Δ
...java/com/google/cloud/firestore/UpdateBuilder.java 94.70% <97.22%> (-0.56%) 57.00 <15.00> (-13.00)
.../com/google/cloud/firestore/DocumentTransform.java 98.03% <100.00%> (-0.18%) 22.00 <2.00> (ø)
...ain/java/com/google/cloud/firestore/FieldMask.java 84.37% <0.00%> (-3.13%) 14.00% <0.00%> (-1.00%)
...a/com/google/cloud/firestore/DocumentSnapshot.java 83.05% <0.00%> (ø) 53.00% <0.00%> (-2.00%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7c86b71...069eba2. Read the comment docs.

@thebrianchen thebrianchen added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 16, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 16, 2020
@thebrianchen thebrianchen added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 18, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 18, 2020
@BenWhitehead
Copy link
Collaborator

Pinged someone to update the branch protection settings to unblock this.

@thebrianchen thebrianchen self-assigned this May 18, 2020
@thebrianchen thebrianchen added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 18, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label May 18, 2020
@BenWhitehead BenWhitehead merged commit 46a3c51 into master May 19, 2020
@BenWhitehead BenWhitehead deleted the bc/update-proto branch May 19, 2020 19:17
gcf-merge-on-green bot pushed a commit that referenced this pull request Jun 4, 2020
🤖 I have created a release \*beep\* \*boop\* 
---
## [1.34.0](https://www.github.com/googleapis/java-firestore/compare/v1.33.0...v1.34.0) (2020-05-29)


### Features

* add support for BigDecimal to CustomClassMapper ([#196](https://www.github.com/googleapis/java-firestore/issues/196)) ([a471f1e](https://www.github.com/googleapis/java-firestore/commit/a471f1eed1e555e95b3d9bcda31ce0277e35a14a))
* Create CODEOWNERS ([#207](https://www.github.com/googleapis/java-firestore/issues/207)) ([cd19eae](https://www.github.com/googleapis/java-firestore/commit/cd19eae68a4898a53c6c3cc8189eab30545a661d))


### Bug Fixes

* add RateLimiter ([#230](https://www.github.com/googleapis/java-firestore/issues/230)) ([47d4a11](https://www.github.com/googleapis/java-firestore/commit/47d4a11625d5888d6f31e494923853a08bb8af77))
* catch null Firestore in system tests ([#215](https://www.github.com/googleapis/java-firestore/issues/215)) ([2a4a7b5](https://www.github.com/googleapis/java-firestore/commit/2a4a7b50d40ff1c165e3d359d5f4eaf929f6ffbc))
* Fields used in whereIn should be equality filters ([#216](https://www.github.com/googleapis/java-firestore/issues/216)) ([4a62633](https://www.github.com/googleapis/java-firestore/commit/4a626333e5af0d70a4dc4853ed373dcf50ea0f4a))
* replace usages of transform proto with update_transform ([#213](https://www.github.com/googleapis/java-firestore/issues/213)) ([46a3c51](https://www.github.com/googleapis/java-firestore/commit/46a3c51386b57f20bd65c564e93181e9ce399e2b))
* support array of references for IN queries ([#211](https://www.github.com/googleapis/java-firestore/issues/211)) ([b376003](https://www.github.com/googleapis/java-firestore/commit/b3760032952529f148065928c3bf13ff73a34edd))


### Dependencies

* update core dependencies to v1.93.5 ([#229](https://www.github.com/googleapis/java-firestore/issues/229)) ([b078213](https://www.github.com/googleapis/java-firestore/commit/b078213209f3936cfe9c9e2cdea040c1262621d4))
* update dependency com.google.api:api-common to v1.9.1 ([#228](https://www.github.com/googleapis/java-firestore/issues/228)) ([7e4568d](https://www.github.com/googleapis/java-firestore/commit/7e4568d8b3f0fc6f591640ccc2d646eb2764e572))
* update dependency com.google.api.grpc:proto-google-common-protos to v1.18.0 ([#204](https://www.github.com/googleapis/java-firestore/issues/204)) ([1e05de4](https://www.github.com/googleapis/java-firestore/commit/1e05de4ecfde055a1c84c2f6dd338604b8580a61))
* update dependency com.google.cloud:google-cloud-conformance-tests to v0.0.10 ([#197](https://www.github.com/googleapis/java-firestore/issues/197)) ([69372af](https://www.github.com/googleapis/java-firestore/commit/69372af7253564691b291766e2bf4d80e9ecc770))
* update dependency com.google.guava:guava-bom to v29 ([#180](https://www.github.com/googleapis/java-firestore/issues/180)) ([3c204b4](https://www.github.com/googleapis/java-firestore/commit/3c204b42ddfbe435ac095368d1e695ed282280bd))
* update dependency io.grpc:grpc-bom to v1.29.0 ([#206](https://www.github.com/googleapis/java-firestore/issues/206)) ([5d8c50f](https://www.github.com/googleapis/java-firestore/commit/5d8c50f105649100abf4fa7a6882bb0469ccbf8f))
* update dependency org.threeten:threetenbp to v1.4.4 ([#194](https://www.github.com/googleapis/java-firestore/issues/194)) ([c867bd5](https://www.github.com/googleapis/java-firestore/commit/c867bd5772aa4a4710c622546e69fdc0f1ca22b6))
* update jackson dependencies to v2.11.0 ([#195](https://www.github.com/googleapis/java-firestore/issues/195)) ([5066812](https://www.github.com/googleapis/java-firestore/commit/50668126e99422cc9498b317c9c76a80a8bf7b30))
* update protobuf.version to v3.12.0 ([#220](https://www.github.com/googleapis/java-firestore/issues/220)) ([2c0b35d](https://www.github.com/googleapis/java-firestore/commit/2c0b35dfc5786b986b5301a00f06177f527496c3))
* update protobuf.version to v3.12.2 ([#226](https://www.github.com/googleapis/java-firestore/issues/226)) ([2eeea19](https://www.github.com/googleapis/java-firestore/commit/2eeea193d7eb54b1efa92b4d5dd996c170048a73))


### Documentation

* update README to include code formatting ([#209](https://www.github.com/googleapis/java-firestore/issues/209)) ([04f8b3b](https://www.github.com/googleapis/java-firestore/commit/04f8b3b0f873c2f1988c184de1e5268e0de9053f))
---


This PR was generated with [Release Please](https://github.com/googleapis/release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants