Skip to content

Conversation

@pmakani
Copy link

@pmakani pmakani commented Nov 20, 2019

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 20, 2019
@codecov
Copy link

codecov bot commented Nov 20, 2019

Codecov Report

Merging #6843 into master will increase coverage by 9.87%.
The diff coverage is 50%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #6843       +/-   ##
============================================
+ Coverage     45.72%   55.6%    +9.87%     
+ Complexity    26528   10548    -15980     
============================================
  Files          2615     774     -1841     
  Lines        282766   88523   -194243     
  Branches      32745    8080    -24665     
============================================
- Hits         129299   49223    -80076     
+ Misses       143350   37082   -106268     
+ Partials      10117    2218     -7899
Impacted Files Coverage Δ Complexity Δ
.../com/google/cloud/firestore/DocumentReference.java 71.25% <ø> (-2.01%) 28 <0> (-3)
...om/google/cloud/firestore/CollectionReference.java 50% <ø> (ø) 9 <0> (-1) ⬇️
...a/com/google/cloud/firestore/DocumentSnapshot.java 82.75% <0%> (-2.2%) 55 <0> (ø)
...java/com/google/cloud/firestore/UpdateBuilder.java 95.19% <71.42%> (-0.05%) 67 <6> (-3)
...m/google/cloud/tasks/v2beta3/CloudTasksClient.java 57.43% <0%> (-2.68%) 67% <0%> (+16%)
...va/com/google/cloud/tasks/v2/CloudTasksClient.java 57.43% <0%> (-2.68%) 67% <0%> (+16%)
...m/google/cloud/tasks/v2beta2/CloudTasksClient.java 57.14% <0%> (-2.39%) 79% <0%> (+19%)
...oogle/cloud/firestore/v1/FirestoreAdminClient.java 59.84% <0%> (-2.23%) 38% <0%> (+8%)
.../cloud/scheduler/v1beta1/CloudSchedulerClient.java 55% <0%> (-2.15%) 35% <0%> (+8%)
...oogle/cloud/scheduler/v1/CloudSchedulerClient.java 55% <0%> (-2.15%) 35% <0%> (+8%)
... and 2142 more

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 5a2c0ae...3836ee1. Read the comment docs.

* automatically.
*
* @param fields A Map containing the data for the new document.
* @param fields A Map or a POJO containing the data for the new document.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: "a map or a POJO" and no period at end of comment since it's not a complete sentence

*/
@Nonnull
public ApiFuture<DocumentReference> add(@Nonnull final Map<String, Object> fields) {
public ApiFuture<DocumentReference> add(@Nonnull final Object fields) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a breaking API change. Is that true? If so, this would require a major version bump.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see why this would be breaking - do you have an example?

Copy link
Contributor

@BenWhitehead BenWhitehead left a comment

Choose a reason for hiding this comment

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

I ran a clirr check locally[1] and received the following errors:

[ERROR] 7002: com.google.cloud.firestore.CollectionReference: Method 'public com.google.api.core.ApiFuture add(java.util.Map)' has been removed
[ERROR] 7002: com.google.cloud.firestore.DocumentReference: Method 'public com.google.api.core.ApiFuture create(java.util.Map)' has been removed
[ERROR] 7002: com.google.cloud.firestore.DocumentReference: Method 'public com.google.api.core.ApiFuture set(java.util.Map)' has been removed
[ERROR] 7002: com.google.cloud.firestore.DocumentReference: Method 'public com.google.api.core.ApiFuture set(java.util.Map, com.google.cloud.firestore.SetOptions)' has been removed
[ERROR] 7005: com.google.cloud.firestore.DocumentReference: Parameter 1 of 'public com.google.api.core.ApiFuture update(java.util.Map)' has changed its type to java.lang.Object
[ERROR] 7005: com.google.cloud.firestore.DocumentReference: Parameter 1 of 'public com.google.api.core.ApiFuture update(java.util.Map, com.google.cloud.firestore.Precondition)' has changed its type to java.lang.Object
[ERROR] 7002: com.google.cloud.firestore.UpdateBuilder: Method 'public com.google.cloud.firestore.UpdateBuilder create(com.google.cloud.firestore.DocumentReference, java.util.Map)' has been removed
[ERROR] 7002: com.google.cloud.firestore.UpdateBuilder: Method 'public com.google.cloud.firestore.UpdateBuilder set(com.google.cloud.firestore.DocumentReference, java.util.Map)' has been removed
[ERROR] 7002: com.google.cloud.firestore.UpdateBuilder: Method 'public com.google.cloud.firestore.UpdateBuilder set(com.google.cloud.firestore.DocumentReference, java.util.Map, com.google.cloud.firestore.SetOptions)' has been removed
[ERROR] 7005: com.google.cloud.firestore.UpdateBuilder: Parameter 2 of 'public com.google.cloud.firestore.UpdateBuilder update(com.google.cloud.firestore.DocumentReference, java.util.Map)' has changed its type to java.lang.Object
[ERROR] 7005: com.google.cloud.firestore.UpdateBuilder: Parameter 2 of 'public com.google.cloud.firestore.UpdateBuilder update(com.google.cloud.firestore.DocumentReference, java.util.Map, com.google.cloud.firestore.Precondition)' has changed its type to java.lang.Object

I think we need to keep all of the existing surface methods, and treat the new methods as overloaded. When method dispatch happens the most specific method should be invoked.

[1] mvn -Dmaven.test.skip.exec=true clean install && mvn --projects :google-cloud-firestore --also-make clirr:check

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.

Thank you! We need to clean up the update handling, but otherwise this is great.

*/
@Nonnull
public ApiFuture<WriteResult> update(@Nonnull Map<String, Object> fields) {
public ApiFuture<WriteResult> update(@Nonnull Object fields) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Updates still needs to take in a Map of <String,Object> and should not accept top-level POJOs (nested POJOs are ok). The reason for this is that update() treats the keys of the fields map as field paths and not as string literals. If you passed a POJO with a property name of "foo.bar", update() would actually updated the nested field "bar" in map "foo".

*
* @param documentReference The DocumentReference to overwrite.
* @param fields A map of the field paths and values for the document.
* @param fields The (Map or POJO) that will be used to populate the document contents.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please drop the parenthesis.

public T update(
@Nonnull DocumentReference documentReference, @Nonnull Map<String, Object> fields) {
public T update(@Nonnull DocumentReference documentReference, @Nonnull Object fields) {
Object data = CustomClassMapper.convertToPlainJavaTypes(fields);
Copy link
Contributor

Choose a reason for hiding this comment

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

As stated above, the top-level fields value should be a Map, but individual values can be custom POJOs.

@schmidt-sebastian
Copy link
Contributor

I think we need to keep all of the existing surface methods, and treat the new methods as overloaded. When method dispatch happens the most specific method should be invoked.

[1] mvn -Dmaven.test.skip.exec=true clean install && mvn --projects :google-cloud-firestore --also-make clirr:check

This seems like a problem with the tooling. We rolled a similar change out on Android without a major version bump: https://github.com/firebase/firebase-android-sdk/pull/76/files

@pmakani pmakani added the type: process A process-related concern. May include testing, release, or the like. label Nov 22, 2019
@pmakani pmakani removed the type: process A process-related concern. May include testing, release, or the like. label Nov 25, 2019
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.

Thank you!

@BenWhitehead BenWhitehead merged commit 6427235 into googleapis:master Nov 25, 2019
@pmakani pmakani deleted the pojo-field-writes branch November 26, 2019 04:37
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.

Firestore: support updating an individual field with pojo as a value

5 participants