Search in sources :

Example 41 with Query

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

the class TargetIndexMatcherTest method withInAndNotIn.

@Test
public void withInAndNotIn() {
    Query q = query("collId").filter(filter("a", "not-in", Arrays.asList(1, 2, 3))).filter(filter("b", "in", Arrays.asList(1, 2, 3)));
    validateServesTarget(q, "a", FieldIndex.Segment.Kind.ASCENDING);
    validateServesTarget(q, "b", FieldIndex.Segment.Kind.ASCENDING);
    validateServesTarget(q, "b", FieldIndex.Segment.Kind.ASCENDING, "a", FieldIndex.Segment.Kind.ASCENDING);
    // If provided, equalities have to come first
    validateDoesNotServeTarget(q, "a", FieldIndex.Segment.Kind.ASCENDING, "b", FieldIndex.Segment.Kind.ASCENDING);
}
Also used : Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 42 with Query

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

the class TargetIndexMatcherTest method withInAndOrderBySameField.

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

Example 43 with Query

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

the class TargetIndexMatcherTest method cannotUseOverspecifiedIndex.

@Test
public void cannotUseOverspecifiedIndex() {
    Query q = query("collId").orderBy(orderBy("a"));
    validateServesTarget(q, "a", FieldIndex.Segment.Kind.ASCENDING);
    validateDoesNotServeTarget(q, "a", FieldIndex.Segment.Kind.ASCENDING, "b", FieldIndex.Segment.Kind.ASCENDING);
}
Also used : Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 44 with Query

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

the class TargetIndexMatcherTest method withMultipleEqualities.

@Test
public void withMultipleEqualities() {
    Query queriesMultipleFilters = query("collId").filter(filter("a1", "==", "a")).filter(filter("a2", "==", "b"));
    validateServesTarget(queriesMultipleFilters, "a1", FieldIndex.Segment.Kind.ASCENDING, "a2", FieldIndex.Segment.Kind.ASCENDING);
    validateServesTarget(queriesMultipleFilters, "a2", FieldIndex.Segment.Kind.ASCENDING, "a1", FieldIndex.Segment.Kind.ASCENDING);
    validateDoesNotServeTarget(queriesMultipleFilters, "a1", FieldIndex.Segment.Kind.ASCENDING, "a2", FieldIndex.Segment.Kind.ASCENDING, "a3", FieldIndex.Segment.Kind.ASCENDING);
}
Also used : Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 45 with Query

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

the class TargetIndexMatcherTest method multipleFiltersRequireMatchingPrefix.

@Test
public void multipleFiltersRequireMatchingPrefix() {
    Query queriesMultipleFilters = query("collId").filter(filter("a", "==", "a")).filter(filter("b", ">", "b"));
    validateServesTarget(queriesMultipleFilters, "b", FieldIndex.Segment.Kind.ASCENDING);
    validateDoesNotServeTarget(queriesMultipleFilters, "c", FieldIndex.Segment.Kind.ASCENDING, "a", 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