Search in sources :

Example 36 with Query

use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.

the class RemoteSerializerTest method unaryFilterTest.

private void unaryFilterTest(String op, Object equalityValue, UnaryFilter.Operator unaryOperator) {
    Query q = Query.atPath(ResourcePath.fromString("docs")).filter(filter("prop", op, equalityValue));
    Target actual = serializer.encodeTarget(wrapTargetData(q));
    StructuredQuery.Builder structuredQueryBuilder = StructuredQuery.newBuilder().addFrom(CollectionSelector.newBuilder().setCollectionId("docs")).setWhere(Filter.newBuilder().setUnaryFilter(UnaryFilter.newBuilder().setField(FieldReference.newBuilder().setFieldPath("prop")).setOp(unaryOperator)));
    // Add extra ORDER_BY field for '!=' since it is an inequality.
    if (op.equals("!=")) {
        structuredQueryBuilder.addOrderBy(Order.newBuilder().setDirection(Direction.ASCENDING).setField(FieldReference.newBuilder().setFieldPath("prop")));
    }
    structuredQueryBuilder.addOrderBy(defaultKeyOrder());
    QueryTarget.Builder queryBuilder = QueryTarget.newBuilder().setParent("projects/p/databases/d/documents").setStructuredQuery(structuredQueryBuilder);
    Target expected = Target.newBuilder().setQuery(queryBuilder).setTargetId(1).setResumeToken(ByteString.EMPTY).build();
    assertEquals(expected, actual);
    assertEquals(serializer.decodeQueryTarget(serializer.encodeQueryTarget(q.toTarget())), q.toTarget());
}
Also used : StructuredQuery(com.google.firestore.v1.StructuredQuery) QueryTarget(com.google.firestore.v1.Target.QueryTarget) DocumentsTarget(com.google.firestore.v1.Target.DocumentsTarget) Target(com.google.firestore.v1.Target) QueryTarget(com.google.firestore.v1.Target.QueryTarget) StructuredQuery(com.google.firestore.v1.StructuredQuery) Query(com.google.firebase.firestore.core.Query)

Example 37 with Query

use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.

the class RemoteSerializerTest method testEncodesListenRequestLabels.

@Test
public void testEncodesListenRequestLabels() {
    Query query = query("collection/key");
    TargetData targetData = new TargetData(query.toTarget(), 2, 3, QueryPurpose.LISTEN);
    Map<String, String> result = serializer.encodeListenRequestLabels(targetData);
    assertNull(result);
    targetData = new TargetData(query.toTarget(), 2, 3, QueryPurpose.LIMBO_RESOLUTION);
    result = serializer.encodeListenRequestLabels(targetData);
    assertEquals(map("goog-listen-tags", "limbo-document"), result);
    targetData = new TargetData(query.toTarget(), 2, 3, QueryPurpose.EXISTENCE_FILTER_MISMATCH);
    result = serializer.encodeListenRequestLabels(targetData);
    assertEquals(map("goog-listen-tags", "existence-filter-mismatch"), result);
}
Also used : TargetData(com.google.firebase.firestore.local.TargetData) StructuredQuery(com.google.firestore.v1.StructuredQuery) Query(com.google.firebase.firestore.core.Query) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 38 with Query

use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.

the class TargetIndexMatcherTest method withMultipleOrderBys.

@Test
public void withMultipleOrderBys() {
    Query q = query("collId").orderBy(orderBy("fff")).orderBy(orderBy("bar", "desc")).orderBy(orderBy("__name__"));
    validateServesTarget(q, "fff", FieldIndex.Segment.Kind.ASCENDING, "bar", FieldIndex.Segment.Kind.DESCENDING, "__name__", FieldIndex.Segment.Kind.ASCENDING);
    validateDoesNotServeTarget(q, "fff", FieldIndex.Segment.Kind.ASCENDING, "__name__", FieldIndex.Segment.Kind.ASCENDING, "bar", FieldIndex.Segment.Kind.DESCENDING);
    q = query("collId").orderBy(orderBy("foo")).orderBy(orderBy("bar")).orderBy(orderBy("__name__", "desc"));
    validateServesTarget(q, "foo", FieldIndex.Segment.Kind.ASCENDING, "bar", FieldIndex.Segment.Kind.ASCENDING, "__name__", FieldIndex.Segment.Kind.DESCENDING);
    validateDoesNotServeTarget(q, "foo", FieldIndex.Segment.Kind.ASCENDING, "__name__", FieldIndex.Segment.Kind.DESCENDING, "bar", FieldIndex.Segment.Kind.ASCENDING);
}
Also used : Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 39 with Query

use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.

the class TargetIndexMatcherTest method withEqualityAndDescendingOrder.

@Test
public void withEqualityAndDescendingOrder() {
    Query q = query("collId").filter(filter("a", "==", 1)).orderBy(orderBy("__name__", "desc"));
    validateServesTarget(q, "a", FieldIndex.Segment.Kind.ASCENDING, "__name__", FieldIndex.Segment.Kind.DESCENDING);
}
Also used : Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 40 with Query

use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.

the class TargetIndexMatcherTest method withInAndOrderBy.

@Test
public void withInAndOrderBy() {
    Query q = query("collId").filter(filter("a", "not-in", Arrays.asList(1, 2, 3))).orderBy(orderBy("a")).orderBy(orderBy("b"));
    validateServesTarget(q, "a", FieldIndex.Segment.Kind.ASCENDING, "b", FieldIndex.Segment.Kind.ASCENDING);
}
Also used : Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Aggregations

Query (com.google.firebase.firestore.core.Query)189 Test (org.junit.Test)179 BundledQuery (com.google.firebase.firestore.bundle.BundledQuery)40 NamedQuery (com.google.firebase.firestore.bundle.NamedQuery)39 StructuredQuery (com.google.firestore.v1.StructuredQuery)16 Target (com.google.firestore.v1.Target)13 DocumentsTarget (com.google.firestore.v1.Target.DocumentsTarget)13 QueryTarget (com.google.firestore.v1.Target.QueryTarget)13 DocumentSet (com.google.firebase.firestore.model.DocumentSet)12 MutableDocument (com.google.firebase.firestore.model.MutableDocument)8 ArrayList (java.util.ArrayList)8 TargetData (com.google.firebase.firestore.local.TargetData)7 FieldIndex (com.google.firebase.firestore.model.FieldIndex)7 DocumentKey (com.google.firebase.firestore.model.DocumentKey)6 ByteString (com.google.protobuf.ByteString)5 Document (com.google.firebase.firestore.model.Document)4 HashMap (java.util.HashMap)4 Target (com.google.firebase.firestore.core.Target)3 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)3 Map (java.util.Map)3