Search in sources :

Example 11 with FieldIndex

use of com.google.firebase.firestore.model.FieldIndex 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, /* byQuery= */
    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 12 with FieldIndex

use of com.google.firebase.firestore.model.FieldIndex in project firebase-android-sdk by firebase.

the class SQLiteLocalStoreTest method testAddsIndexes.

@Test
public void testAddsIndexes() {
    FieldIndex indexA = fieldIndex("coll", 0, FieldIndex.INITIAL_STATE, "a", FieldIndex.Segment.Kind.ASCENDING);
    FieldIndex indexB = fieldIndex("coll", 1, FieldIndex.INITIAL_STATE, "b", FieldIndex.Segment.Kind.DESCENDING);
    FieldIndex indexC = fieldIndex("coll", 2, FieldIndex.INITIAL_STATE, "c1", FieldIndex.Segment.Kind.ASCENDING, "c2", FieldIndex.Segment.Kind.CONTAINS);
    configureFieldIndexes(Arrays.asList(indexA, indexB));
    Collection<FieldIndex> fieldIndexes = getFieldIndexes();
    assertThat(fieldIndexes).containsExactly(indexA, indexB);
    configureFieldIndexes(Arrays.asList(indexA, indexC));
    fieldIndexes = getFieldIndexes();
    assertThat(fieldIndexes).containsExactly(indexA, indexC);
}
Also used : FieldIndex(com.google.firebase.firestore.model.FieldIndex) Test(org.junit.Test)

Example 13 with FieldIndex

use of com.google.firebase.firestore.model.FieldIndex 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)

Example 14 with FieldIndex

use of com.google.firebase.firestore.model.FieldIndex 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, /* byQuery= */
    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 15 with FieldIndex

use of com.google.firebase.firestore.model.FieldIndex in project firebase-android-sdk by firebase.

the class IndexBackfillerTest method addFieldIndex.

private void addFieldIndex(String collectionGroup, String fieldName, SnapshotVersion version) {
    FieldIndex fieldIndex = fieldIndex(collectionGroup, FieldIndex.UNKNOWN_ID, FieldIndex.IndexState.create(0, version, DocumentKey.empty(), -1), fieldName, FieldIndex.Segment.Kind.ASCENDING);
    indexManager.addFieldIndex(fieldIndex);
}
Also used : FieldIndex(com.google.firebase.firestore.model.FieldIndex)

Aggregations

FieldIndex (com.google.firebase.firestore.model.FieldIndex)49 Test (org.junit.Test)32 Nullable (androidx.annotation.Nullable)8 Value (com.google.firestore.v1.Value)8 Query (com.google.firebase.firestore.core.Query)6 ArrayList (java.util.ArrayList)6 DocumentKey (com.google.firebase.firestore.model.DocumentKey)3 DirectionalIndexByteEncoder (com.google.firebase.firestore.index.DirectionalIndexByteEncoder)2 IndexByteEncoder (com.google.firebase.firestore.index.IndexByteEncoder)2 IndexEntry (com.google.firebase.firestore.index.IndexEntry)2 IndexOffset (com.google.firebase.firestore.model.FieldIndex.IndexOffset)2 HashMap (java.util.HashMap)2 VisibleForTesting (androidx.annotation.VisibleForTesting)1 Timestamp (com.google.firebase.Timestamp)1 ImmutableSortedMap (com.google.firebase.database.collection.ImmutableSortedMap)1 Bound (com.google.firebase.firestore.core.Bound)1 Target (com.google.firebase.firestore.core.Target)1 Document (com.google.firebase.firestore.model.Document)1 FieldPath (com.google.firebase.firestore.model.FieldPath)1 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)1