use of com.google.firebase.firestore.core.FieldFilter in project firebase-android-sdk by firebase.
the class RemoteSerializerTest method testKeyFieldSerializationEncoding.
@Test
public void testKeyFieldSerializationEncoding() {
FieldFilter inputFilter = filter("__name__", "==", ref("project/database"));
StructuredQuery.Filter apiFilter = serializer.encodeUnaryOrFieldFilter(inputFilter);
StructuredQuery.Filter expectedFilter = Filter.newBuilder().setFieldFilter(StructuredQuery.FieldFilter.newBuilder().setField(FieldReference.newBuilder().setFieldPath("__name__")).setOp(Operator.EQUAL).setValue(Value.newBuilder().setReferenceValue("projects/project/databases/(default)/documents/project/database")).build()).build();
assertEquals(expectedFilter, apiFilter);
FieldFilter roundTripped = serializer.decodeFieldFilter(apiFilter.getFieldFilter());
assertEquals(roundTripped, inputFilter);
assertTrue(roundTripped instanceof KeyFieldFilter);
}
use of com.google.firebase.firestore.core.FieldFilter in project firebase-android-sdk by firebase.
the class RemoteSerializerTest method testNotEqualSerialization.
@Test
public void testNotEqualSerialization() {
FieldFilter inputFilter = filter("field", "!=", 42);
StructuredQuery.Filter apiFilter = serializer.encodeUnaryOrFieldFilter(inputFilter);
StructuredQuery.Filter expectedFilter = Filter.newBuilder().setFieldFilter(StructuredQuery.FieldFilter.newBuilder().setField(FieldReference.newBuilder().setFieldPath("field")).setOp(Operator.NOT_EQUAL).setValue(Value.newBuilder().setIntegerValue(42)).build()).build();
assertEquals(expectedFilter, apiFilter);
FieldFilter roundTripped = serializer.decodeFieldFilter(apiFilter.getFieldFilter());
assertEquals(roundTripped, inputFilter);
}
use of com.google.firebase.firestore.core.FieldFilter in project firebase-android-sdk by firebase.
the class BundleSerializer method decodeFieldFilter.
private void decodeFieldFilter(List<Filter> result, JSONObject fieldFilter) throws JSONException {
FieldPath fieldPath = decodeFieldReference(fieldFilter.getJSONObject("field"));
FieldFilter.Operator filterOperator = decodeFieldFilterOperator(fieldFilter.getString("op"));
result.add(FieldFilter.create(fieldPath, filterOperator, decodeValue(fieldFilter.getJSONObject("value"))));
}
use of com.google.firebase.firestore.core.FieldFilter in project firebase-android-sdk by firebase.
the class RemoteSerializer method decodeFieldFilter.
@VisibleForTesting
FieldFilter decodeFieldFilter(StructuredQuery.FieldFilter proto) {
FieldPath fieldPath = FieldPath.fromServerFormat(proto.getField().getFieldPath());
FieldFilter.Operator filterOperator = decodeFieldFilterOperator(proto.getOp());
return FieldFilter.create(fieldPath, filterOperator, proto.getValue());
}
use of com.google.firebase.firestore.core.FieldFilter in project firebase-android-sdk by firebase.
the class Query method validateNewFilter.
/**
* Checks that adding the given filter to the current query is valid
*/
private void validateNewFilter(com.google.firebase.firestore.core.Filter filter) {
com.google.firebase.firestore.core.Query testQuery = query;
for (FieldFilter subfilter : filter.getFlattenedFilters()) {
validateNewFieldFilter(testQuery, subfilter);
testQuery = query.filter(subfilter);
}
}
Aggregations