Skip to content

Commit

Permalink
Update Protobuf to use increment()
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidt-sebastian committed Dec 26, 2018
1 parent 29758d1 commit c7e8172
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,9 @@ private void parseSentinelFieldValue(
numericIncrementFieldValue =
(com.google.firebase.firestore.FieldValue.NumericIncrementFieldValue) value;
NumberValue operand = (NumberValue) parseQueryValue(numericIncrementFieldValue.getOperand());
NumericIncrementTransformOperation numericAdd =
NumericIncrementTransformOperation incrementOperation =
new NumericIncrementTransformOperation(operand);
context.addToFieldTransforms(context.getPath(), numericAdd);
context.addToFieldTransforms(context.getPath(), incrementOperation);

} else {
throw Assert.fail("Unknown FieldValue type: %s", Util.typeName(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import com.google.firebase.firestore.remote.TargetChange;
import com.google.firebase.firestore.util.Logger;
import com.google.protobuf.ByteString;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.google.firebase.firestore.model.FieldPath;
import com.google.firebase.firestore.model.value.FieldValue;
import com.google.firebase.firestore.model.value.ObjectValue;

import java.util.Set;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import com.google.firebase.firestore.model.value.FieldValue;
import com.google.firebase.firestore.model.value.ObjectValue;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.Nullable;

/**
Expand Down Expand Up @@ -123,11 +125,11 @@ public MaybeDocument applyToLocalView(

@Override
public FieldMask getFieldMask() {
List<FieldPath> fieldMask = new ArrayList<>();
Set<FieldPath> fieldMask = new HashSet<>();
for (FieldTransform transform : fieldTransforms) {
fieldMask.add(transform.getFieldPath());
}
return FieldMask.fromCollection(fieldMask);
return FieldMask.fromSet(fieldMask);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,11 @@ private DocumentTransform.FieldTransform encodeFieldTransform(FieldTransform fie
.setRemoveAllFromArray(encodeArrayTransformElements(remove.getElements()))
.build();
} else if (transform instanceof NumericIncrementTransformOperation) {
NumericIncrementTransformOperation numericAdd =
NumericIncrementTransformOperation incrementOperation =
(NumericIncrementTransformOperation) transform;
return DocumentTransform.FieldTransform.newBuilder()
.setFieldPath(fieldTransform.getFieldPath().canonicalString())
.setNumericAdd(encodeValue(numericAdd.getOperand()))
.setIncrement(encodeValue(incrementOperation.getOperand()))
.build();
} else {
throw fail("Unknown transform: %s", transform);
Expand Down Expand Up @@ -605,17 +605,17 @@ private FieldTransform decodeFieldTransform(DocumentTransform.FieldTransform fie
FieldPath.fromServerFormat(fieldTransform.getFieldPath()),
new ArrayTransformOperation.Remove(
decodeArrayTransformElements(fieldTransform.getRemoveAllFromArray())));
case NUMERIC_ADD:
case INCREMENT:
{
FieldValue operand = decodeValue(fieldTransform.getNumericAdd());
FieldValue operand = decodeValue(fieldTransform.getIncrement());
hardAssert(
operand instanceof NumberValue,
"Expected NUMERIC_ADD transform to be of number type, but was %s",
operand.getClass().getCanonicalName());
return new FieldTransform(
FieldPath.fromServerFormat(fieldTransform.getFieldPath()),
new NumericIncrementTransformOperation(
(NumberValue) decodeValue(fieldTransform.getNumericAdd())));
(NumberValue) decodeValue(fieldTransform.getIncrement())));
}
default:
throw fail("Unknown FieldTransform proto: %s", fieldTransform);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ message DocumentTransform {
//
// This must be an integer or a double value.
// If the field is not an integer or double, or if the field does not yet
// exist, the transformation will set the field to the given value.
// exist, the transformation will set the field to the given value.n
// If either of the given value or the current field value are doubles,
// both values will be interpreted as doubles. Double arithmetic and
// representation of double values follow IEEE 754 semantics.
// If there is positive/negative integer overflow, the field is resolved
// to the largest magnitude positive/negative integer.
Value numeric_add = 3;
Value increment = 3;

// Append the given elements in order if they are not already present in
// the current field value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static com.google.firebase.firestore.testutil.TestUtil.deleteMutation;
import static com.google.firebase.firestore.testutil.TestUtil.deletedDoc;
import static com.google.firebase.firestore.testutil.TestUtil.doc;
import static com.google.firebase.firestore.testutil.TestUtil.field;
import static com.google.firebase.firestore.testutil.TestUtil.fieldMask;
import static com.google.firebase.firestore.testutil.TestUtil.key;
import static com.google.firebase.firestore.testutil.TestUtil.map;
Expand All @@ -33,6 +34,7 @@
import com.google.firebase.firestore.model.NoDocument;
import com.google.firebase.firestore.model.SnapshotVersion;
import com.google.firebase.firestore.model.UnknownDocument;
import com.google.firebase.firestore.model.mutation.FieldMask;
import com.google.firebase.firestore.model.mutation.Mutation;
import com.google.firebase.firestore.model.mutation.MutationBatch;
import com.google.firebase.firestore.model.mutation.PatchMutation;
Expand Down Expand Up @@ -70,7 +72,7 @@ public void testEncodesMutationBatch() {
new PatchMutation(
key("foo/bar"),
TestUtil.wrapObject(map("a", "b")),
FieldMask.fromCollection(asList(field("a"))),
FieldMask.fromSet(Collections.singleton(field("a"))),
com.google.firebase.firestore.model.mutation.Precondition.NONE);
Mutation set = setMutation("foo/bar", map("a", "b", "num", 1));
Mutation patch =
Expand Down

0 comments on commit c7e8172

Please sign in to comment.