Search in sources :

Example 76 with Query

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

the class SQLiteIndexManagerTest method testOrderByKeyFilter.

@Test
public void testOrderByKeyFilter() {
    indexManager.addFieldIndex(fieldIndex("coll", "count", Kind.ASCENDING));
    indexManager.addFieldIndex(fieldIndex("coll", "count", Kind.DESCENDING));
    addDoc("coll/val1", map("count", 1));
    addDoc("coll/val2", map("count", 1));
    addDoc("coll/val3", map("count", 3));
    Query query = query("coll").orderBy(orderBy("count"));
    verifyResults(query, "coll/val1", "coll/val2", "coll/val3");
    query = query("coll").orderBy(orderBy("count", "desc"));
    verifyResults(query, "coll/val3", "coll/val2", "coll/val1");
}
Also used : Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 77 with Query

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

the class SQLiteLocalStoreTest method testUsesPartiallyIndexedRemoteDocumentsWhenAvailable.

@Test
public void testUsesPartiallyIndexedRemoteDocumentsWhenAvailable() {
    FieldIndex index = fieldIndex("coll", 0, FieldIndex.INITIAL_STATE, "matches", FieldIndex.Segment.Kind.ASCENDING);
    configureFieldIndexes(singletonList(index));
    Query query = query("coll").filter(filter("matches", "==", true));
    int targetId = allocateQuery(query);
    applyRemoteEvent(addedRemoteEvent(doc("coll/a", 10, map("matches", true)), targetId));
    backfillIndexes();
    applyRemoteEvent(addedRemoteEvent(doc("coll/b", 20, map("matches", true)), targetId));
    executeQuery(query);
    assertRemoteDocumentsRead(/* byKey= */
    1, /* byCollection= */
    1);
    assertQueryReturned("coll/a", "coll/b");
}
Also used : FieldIndex(com.google.firebase.firestore.model.FieldIndex) Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 78 with Query

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

the class SQLiteLocalStoreTest method testUsesIndexes.

@Test
public void testUsesIndexes() {
    FieldIndex index = fieldIndex("coll", 0, FieldIndex.INITIAL_STATE, "matches", FieldIndex.Segment.Kind.ASCENDING);
    configureFieldIndexes(singletonList(index));
    Query query = query("coll").filter(filter("matches", "==", true));
    int targetId = allocateQuery(query);
    applyRemoteEvent(addedRemoteEvent(doc("coll/a", 10, map("matches", true)), targetId));
    backfillIndexes();
    executeQuery(query);
    assertRemoteDocumentsRead(/* byKey= */
    1, /* byCollection= */
    0);
    assertQueryReturned("coll/a");
}
Also used : FieldIndex(com.google.firebase.firestore.model.FieldIndex) Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 79 with Query

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

the class SQLiteLocalStoreTest method testUsesIndexForLimitQueryWhenIndexIsUpdated.

@Test
public void testUsesIndexForLimitQueryWhenIndexIsUpdated() {
    FieldIndex index = fieldIndex("coll", 0, FieldIndex.INITIAL_STATE, "count", FieldIndex.Segment.Kind.ASCENDING);
    configureFieldIndexes(singletonList(index));
    Query query = query("coll").orderBy(orderBy("count")).limitToFirst(2);
    int targetId = allocateQuery(query);
    applyRemoteEvent(addedRemoteEvent(Arrays.asList(doc("coll/a", 10, map("count", 1)), doc("coll/b", 10, map("count", 2)), doc("coll/c", 10, map("count", 3))), Collections.singletonList(targetId), Collections.emptyList()));
    writeMutation(deleteMutation("coll/b"));
    backfillIndexes();
    executeQuery(query);
    assertRemoteDocumentsRead(/* byKey= */
    2, /* byCollection= */
    0);
    assertOverlaysRead(/* byKey= */
    2, /* byCollection= */
    0);
    assertQueryReturned("coll/a", "coll/c");
}
Also used : FieldIndex(com.google.firebase.firestore.model.FieldIndex) Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 80 with Query

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

the class SQLiteLocalStoreTest method testUsesPartiallyIndexedOverlaysWhenAvailable.

@Test
public void testUsesPartiallyIndexedOverlaysWhenAvailable() {
    FieldIndex index = fieldIndex("coll", 0, FieldIndex.INITIAL_STATE, "matches", FieldIndex.Segment.Kind.ASCENDING);
    configureFieldIndexes(singletonList(index));
    writeMutation(setMutation("coll/a", map("matches", true)));
    backfillIndexes();
    writeMutation(setMutation("coll/b", map("matches", true)));
    Query query = query("coll").filter(filter("matches", "==", true));
    executeQuery(query);
    assertOverlaysRead(/* byKey= */
    1, /* byCollection= */
    1);
    assertQueryReturned("coll/a", "coll/b");
}
Also used : FieldIndex(com.google.firebase.firestore.model.FieldIndex) Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Aggregations

Query (com.google.firebase.firestore.core.Query)205 Test (org.junit.Test)195 BundledQuery (com.google.firebase.firestore.bundle.BundledQuery)42 NamedQuery (com.google.firebase.firestore.bundle.NamedQuery)41 DocumentSet (com.google.firebase.firestore.model.DocumentSet)18 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 MutableDocument (com.google.firebase.firestore.model.MutableDocument)12 FieldIndex (com.google.firebase.firestore.model.FieldIndex)8 TargetData (com.google.firebase.firestore.local.TargetData)7 ArrayList (java.util.ArrayList)7 DocumentKey (com.google.firebase.firestore.model.DocumentKey)5 ByteString (com.google.protobuf.ByteString)5 HashMap (java.util.HashMap)4 Document (com.google.firebase.firestore.model.Document)3 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)3 Timestamp (com.google.firebase.Timestamp)2 QueryListener (com.google.firebase.firestore.core.QueryListener)2