Skip to content

Add an ObjectValue builder #1150

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

Merged

Conversation

schmidt-sebastian
Copy link
Contributor

This PR is meant to pave the way for a mutable ObjectValue that is based on a Value.Builder. It proves that we only need set() and delete() (and not equals() and compareTo()) on the mutable type since most parts of the code still deal with immutable ObjectValues.

This is meant for an feature branch until we finish the Proto conversion as ObjectValue.Builder().set() is somewhat inefficient for nested field updates.

@googlebot googlebot added the cla: yes Override cla label Jan 21, 2020
@schmidt-sebastian schmidt-sebastian changed the base branch from master to mrschmidt/rewritefieldvalue January 21, 2020 23:03
@codecov
Copy link

codecov bot commented Jan 21, 2020

Codecov Report

Merging #1150 into mrschmidt/rewritefieldvalue will increase coverage by 9.02%.
The diff coverage is 89.58%.

Flag Coverage Δ Complexity Δ
#Encoders_FirebaseEncodersJson ? ?
#Encoders_FirebaseEncodersProcessor ? ?
#Encoders_FirebaseEncodersReflective ? ?
#FirebaseAbt ? ?
#FirebaseCommon ? ?
#FirebaseCommon_DataCollectionTests ? ?
#FirebaseCommon_Ktx ? ?
#FirebaseComponents ? ?
#FirebaseConfig ? ?
#FirebaseConfig_Ktx ? ?
#FirebaseCrashlytics ? ?
#FirebaseDatabase ? ?
#FirebaseDatabaseCollection ? ?
#FirebaseDatabase_Ktx ? ?
#FirebaseDatatransport ? ?
#FirebaseDynamicLinks ? ?
#FirebaseDynamicLinks_Ktx ? ?
#FirebaseFirestore 62.01% <89.58%> (+0.03%) 2279 <13> (-4) ⬇️
#FirebaseFirestore_Ktx 41.17% <ø> (ø) 0 <ø> (ø) ⬇️
#FirebaseFunctions ? ?
#FirebaseFunctions_Ktx ? ?
#FirebaseInappmessaging ? ?
#FirebaseInappmessagingDisplay ? ?
#FirebaseInappmessagingDisplay_Ktx ? ?
#FirebaseInappmessaging_Ktx ? ?
#FirebaseInstallations ? ?
#FirebaseStorage_Ktx ? ?
#Tools_Errorprone ? ?
#Tools_Lint ? ?
#Transport_TransportBackendCct ? ?
#Transport_TransportRuntime ? ?
Impacted Files Coverage Δ Complexity Δ
...le/firebase/firestore/remote/RemoteSerializer.java 79.31% <100%> (ø) 147 <2> (ø) ⬇️
.../com/google/firebase/firestore/model/Document.java 81.69% <100%> (ø) 27 <0> (ø) ⬇️
...rebase/firestore/model/mutation/PatchMutation.java 82.22% <100%> (+0.4%) 16 <3> (ø) ⬇️
...se/firestore/model/mutation/TransformMutation.java 81.92% <100%> (+0.22%) 22 <6> (+1) ⬆️
...m/google/firebase/firestore/UserDataConverter.java 55.67% <50%> (ø) 37 <0> (ø) ⬇️
...le/firebase/firestore/model/value/ObjectValue.java 97.64% <92.3%> (+0.17%) 31 <2> (-5) ⬇️
...ndroid/datatransport/cct/internal/LogResponse.java
...ng/internal/injection/modules/RateLimitModule.java
...ndroid/datatransport/runtime/TransportContext.java
...cs/internal/settings/network/UpdateAppSpiCall.java
... and 473 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 331ec37...4025ada. Read the comment docs.

@@ -117,7 +117,7 @@ public ParsedUpdateData parseUpdateData(Map<String, Object> data) {

ParseAccumulator accumulator = new ParseAccumulator(UserData.Source.Update);
ParseContext context = accumulator.rootContext();
ObjectValue updateData = ObjectValue.emptyObject();
ObjectValue.Builder updateData = ObjectValue.Builder.emptyBuilder();
Copy link
Contributor

Choose a reason for hiding this comment

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

This is pretty verbose. How about ObjectValue.newBuilder()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Works for me. I got inspired by the rest of the Protobuf API.

for (int i = 0; i < fieldTransforms.size(); i++) {
FieldTransform fieldTransform = fieldTransforms.get(i);
FieldPath fieldPath = fieldTransform.getFieldPath();
objectValue = objectValue.set(fieldPath, transformResults.get(i));
builder.set(fieldPath, transformResults.get(i)).build();
Copy link
Contributor

Choose a reason for hiding this comment

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

Trailing .build() here seems wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

@@ -356,4 +374,12 @@ public void testValueOrdering() {
.addEqualityGroup(wrapObject(map("foo", "0")))
.testCompare();
}

private ObjectValue setField(ObjectValue empty, String a, FieldValue mod) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The caller doesn't necessarily have to pass an empty object, do they? Seems like empty could be objectValue, as it is below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it should have been objectValue.

@wilhuff wilhuff assigned schmidt-sebastian and unassigned wilhuff Jan 22, 2020
Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

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

LGTM

@wilhuff wilhuff assigned schmidt-sebastian and unassigned wilhuff Jan 22, 2020
@schmidt-sebastian schmidt-sebastian merged commit baa0a89 into mrschmidt/rewritefieldvalue Jan 23, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/objectbuilder branch February 7, 2020 00:22
@firebase firebase locked and limited conversation to collaborators Feb 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants