Search in sources :

Example 81 with Query

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

the class SQLiteQueryEngineTest method testRefillsIndexedLimitQueries.

@Test
public void testRefillsIndexedLimitQueries() throws Exception {
    MutableDocument doc1 = doc("coll/1", 1, map("a", 1));
    MutableDocument doc2 = doc("coll/2", 1, map("a", 2));
    MutableDocument doc3 = doc("coll/3", 1, map("a", 3));
    MutableDocument doc4 = doc("coll/4", 1, map("a", 4));
    addDocument(doc1, doc2, doc3, doc4);
    indexManager.addFieldIndex(fieldIndex("coll", "a", Kind.ASCENDING));
    indexManager.updateIndexEntries(docMap(doc1, doc2, doc3, doc4));
    indexManager.updateCollectionGroup("coll", IndexOffset.fromDocument(doc4));
    addMutation(patchMutation("coll/3", map("a", 5)));
    Query query = query("coll").orderBy(orderBy("a")).limitToFirst(3);
    DocumentSet result = expectOptimizedCollectionScan(() -> runQuery(query, SnapshotVersion.NONE));
    assertEquals(docSet(query.comparator(), doc1, doc2, doc4), result);
}
Also used : Query(com.google.firebase.firestore.core.Query) MutableDocument(com.google.firebase.firestore.model.MutableDocument) DocumentSet(com.google.firebase.firestore.model.DocumentSet) Test(org.junit.Test)

Example 82 with Query

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

the class BundleSerializerTest method testDecodesCollectionQuery.

// Query decoding tests
@Test
public void testDecodesCollectionQuery() throws JSONException {
    String json = "{ from: [ { collectionId: 'coll' } ] }";
    Query query = TestUtil.query("coll");
    assertDecodesNamedQuery(json, query);
}
Also used : Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 83 with Query

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

the class BundleSerializerTest method testDecodesGreaterThanOrEqualFilter.

@Test
public void testDecodesGreaterThanOrEqualFilter() throws JSONException {
    String json = "{\n" + "from: [ { collectionId: 'coll' } ],\n" + "where: {\n" + "  fieldFilter: {\n" + "    op: 'GREATER_THAN_OR_EQUAL',\n" + "    field: { fieldPath: 'f1' },\n" + "    value: { stringValue: 'foo' }\n" + "  }\n" + "} }";
    Query query = TestUtil.query("coll").filter(filter("f1", ">=", "foo"));
    assertDecodesNamedQuery(json, query);
}
Also used : Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 84 with Query

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

the class BundleSerializerTest method testDecodesNotInFilter.

@Test
public void testDecodesNotInFilter() throws JSONException {
    String json = "{\n" + "from: [ { collectionId: 'coll' } ],\n" + "where: {\n" + "  fieldFilter: {\n" + "    op: 'NOT_IN',\n" + "    field: { fieldPath: 'f1' },\n" + "    value: { arrayValue: { values: [ { stringValue: 'foo' } ] } }\n" + "  }" + "} }";
    Query query = TestUtil.query("coll").filter(filter("f1", "not-in", Collections.singletonList("foo")));
    assertDecodesNamedQuery(json, query);
}
Also used : Query(com.google.firebase.firestore.core.Query) Test(org.junit.Test)

Example 85 with Query

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

the class BundleSerializerTest method testDecodeOrderByQuery.

@Test
public void testDecodeOrderByQuery() throws JSONException {
    String json = "{\n" + "from: [ { collectionId: 'coll' } ],\n" + "orderBy: [\n" + "  { field: { fieldPath: 'f1' }},\n" + "  { field:  { fieldPath: 'f2' }, direction: 'ASCENDING' },\n" + "  { field:  { fieldPath: 'f3' }, direction: 'DESCENDING' }\n" + "]}";
    Query query = TestUtil.query("coll").orderBy(orderBy("f1")).orderBy(orderBy("f2", "asc")).orderBy(orderBy("f3", "desc"));
    assertDecodesNamedQuery(json, query);
}
Also used : 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