Search in sources :

Example 1 with FieldFilter

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);
}
Also used : StructuredQuery(com.google.firestore.v1.StructuredQuery) FieldFilter(com.google.firebase.firestore.core.FieldFilter) KeyFieldFilter(com.google.firebase.firestore.core.KeyFieldFilter) KeyFieldFilter(com.google.firebase.firestore.core.KeyFieldFilter) Filter(com.google.firestore.v1.StructuredQuery.Filter) Test(org.junit.Test)

Example 2 with FieldFilter

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);
}
Also used : StructuredQuery(com.google.firestore.v1.StructuredQuery) FieldFilter(com.google.firebase.firestore.core.FieldFilter) KeyFieldFilter(com.google.firebase.firestore.core.KeyFieldFilter) Filter(com.google.firestore.v1.StructuredQuery.Filter) Test(org.junit.Test)

Example 3 with FieldFilter

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"))));
}
Also used : FieldFilter(com.google.firebase.firestore.core.FieldFilter) FieldPath(com.google.firebase.firestore.model.FieldPath)

Example 4 with FieldFilter

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());
}
Also used : FieldFilter(com.google.firebase.firestore.core.FieldFilter) FieldPath(com.google.firebase.firestore.model.FieldPath) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 5 with FieldFilter

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);
    }
}
Also used : FieldFilter(com.google.firebase.firestore.core.FieldFilter)

Aggregations

FieldFilter (com.google.firebase.firestore.core.FieldFilter)10 KeyFieldFilter (com.google.firebase.firestore.core.KeyFieldFilter)6 StructuredQuery (com.google.firestore.v1.StructuredQuery)6 Filter (com.google.firestore.v1.StructuredQuery.Filter)6 Test (org.junit.Test)6 ArrayValue (com.google.firestore.v1.ArrayValue)5 NotInFilter (com.google.firebase.firestore.core.NotInFilter)3 FieldPath (com.google.firebase.firestore.model.FieldPath)2 VisibleForTesting (androidx.annotation.VisibleForTesting)1 ArrayContainsAnyFilter (com.google.firebase.firestore.core.ArrayContainsAnyFilter)1 Operator (com.google.firebase.firestore.core.FieldFilter.Operator)1 InFilter (com.google.firebase.firestore.core.InFilter)1 Value (com.google.firestore.v1.Value)1 ArrayList (java.util.ArrayList)1