Search in sources :

Example 96 with Query

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

the class QueryEngineTestCase method doesNotUseInitialResultsForLimitQueryWithDocumentRemoval.

@Test
public void doesNotUseInitialResultsForLimitQueryWithDocumentRemoval() throws Exception {
    Query query = query("coll").filter(filter("matches", "==", true)).limitToFirst(1);
    // While the backend would never add DocA to the set of remote keys, this allows us to easily
    // simulate what would happen when a document no longer matches due to an out-of-band update.
    addDocument(NON_MATCHING_DOC_A);
    persistQueryMapping(NON_MATCHING_DOC_A.getKey());
    addDocument(MATCHING_DOC_B);
    DocumentSet docs = expectFullCollectionScan(() -> runQuery(query, LAST_LIMBO_FREE_SNAPSHOT));
    assertEquals(docSet(query.comparator(), MATCHING_DOC_B), docs);
}
Also used : Query(com.google.firebase.firestore.core.Query) DocumentSet(com.google.firebase.firestore.model.DocumentSet) Test(org.junit.Test)

Example 97 with Query

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

the class QueryEngineTestCase method filtersNonMatchingInitialResults.

@Test
public void filtersNonMatchingInitialResults() throws Exception {
    Query query = query("coll").filter(filter("matches", "==", true));
    addDocument(MATCHING_DOC_A, MATCHING_DOC_B);
    persistQueryMapping(MATCHING_DOC_A.getKey(), MATCHING_DOC_B.getKey());
    // Add a mutated document that is not yet part of query's set of remote keys.
    addDocumentWithEventVersion(version(1), NON_MATCHING_DOC_A);
    DocumentSet docs = expectOptimizedCollectionScan(() -> runQuery(query, LAST_LIMBO_FREE_SNAPSHOT));
    assertEquals(docSet(query.comparator(), MATCHING_DOC_B), docs);
}
Also used : Query(com.google.firebase.firestore.core.Query) DocumentSet(com.google.firebase.firestore.model.DocumentSet) Test(org.junit.Test)

Example 98 with Query

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

the class QueryEngineTestCase method doesNotUseInitialResultsForLimitQueryWhenLastDocumentHasBeenUpdatedOutOfBand.

@Test
public void doesNotUseInitialResultsForLimitQueryWhenLastDocumentHasBeenUpdatedOutOfBand() throws Exception {
    Query query = query("coll").filter(filter("matches", "==", true)).orderBy(orderBy("order", "desc")).limitToFirst(1);
    // Add a query mapping for a document that matches, but that sorts below another document based
    // due to an update that the SDK received after the query's snapshot was persisted.
    addDocument(UPDATED_DOC_A);
    persistQueryMapping(UPDATED_DOC_A.getKey());
    addDocument(MATCHING_DOC_B);
    DocumentSet docs = expectFullCollectionScan(() -> runQuery(query, LAST_LIMBO_FREE_SNAPSHOT));
    assertEquals(docSet(query.comparator(), MATCHING_DOC_B), docs);
}
Also used : Query(com.google.firebase.firestore.core.Query) DocumentSet(com.google.firebase.firestore.model.DocumentSet) Test(org.junit.Test)

Example 99 with Query

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

the class QueryEngineTestCase method usesTargetMappingForInitialView.

@Test
public void usesTargetMappingForInitialView() throws Exception {
    Query query = query("coll").filter(filter("matches", "==", true));
    addDocument(MATCHING_DOC_A, MATCHING_DOC_B);
    persistQueryMapping(MATCHING_DOC_A.getKey(), MATCHING_DOC_B.getKey());
    DocumentSet docs = expectOptimizedCollectionScan(() -> runQuery(query, LAST_LIMBO_FREE_SNAPSHOT));
    assertEquals(docSet(query.comparator(), MATCHING_DOC_A, MATCHING_DOC_B), docs);
}
Also used : Query(com.google.firebase.firestore.core.Query) DocumentSet(com.google.firebase.firestore.model.DocumentSet) Test(org.junit.Test)

Example 100 with Query

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

the class QueryEngineTestCase method doesNotUseInitialResultsForUnfilteredCollectionQuery.

@Test
public void doesNotUseInitialResultsForUnfilteredCollectionQuery() throws Exception {
    Query query = query("coll");
    DocumentSet docs = expectFullCollectionScan(() -> runQuery(query, LAST_LIMBO_FREE_SNAPSHOT));
    assertEquals(docSet(query.comparator()), docs);
}
Also used : Query(com.google.firebase.firestore.core.Query) DocumentSet(com.google.firebase.firestore.model.DocumentSet) 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