Search in sources :

Example 16 with Target

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

the class SQLiteIndexManager method getSubTargets.

private List<Target> getSubTargets(Target target) {
    if (targetToDnfSubTargets.containsKey(target)) {
        return targetToDnfSubTargets.get(target);
    }
    List<Target> subTargets = new ArrayList<>();
    if (target.getFilters().isEmpty()) {
        subTargets.add(target);
    } else {
        // There is an implicit AND operation between all the filters stored in the target.
        List<Filter> dnf = LogicUtils.DnfTransform(new CompositeFilter(target.getFilters(), StructuredQuery.CompositeFilter.Operator.AND));
        for (Filter term : dnf) {
            subTargets.add(new Target(target.getPath(), target.getCollectionGroup(), term.getFilters(), target.getOrderBy(), target.getLimit(), target.getStartAt(), target.getEndAt()));
        }
    }
    targetToDnfSubTargets.put(target, subTargets);
    return subTargets;
}
Also used : Target(com.google.firebase.firestore.core.Target) CompositeFilter(com.google.firebase.firestore.core.CompositeFilter) FieldFilter(com.google.firebase.firestore.core.FieldFilter) Filter(com.google.firebase.firestore.core.Filter) CompositeFilter(com.google.firebase.firestore.core.CompositeFilter) ArrayList(java.util.ArrayList)

Example 17 with Target

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

the class IndexBackfillerTest method verifyQueryResults.

private void verifyQueryResults(Query query, String... expectedKeys) {
    Target target = query.toTarget();
    Set<DocumentKey> actualKeys = indexManager.getDocumentsMatchingTarget(target);
    if (actualKeys == null) {
        assertEquals(0, expectedKeys.length);
    } else {
        assertThat(actualKeys).containsExactlyElementsIn(Arrays.stream(expectedKeys).map(TestUtil::key).toArray());
    }
}
Also used : Target(com.google.firebase.firestore.core.Target) TestUtil(com.google.firebase.firestore.testutil.TestUtil) DocumentKey(com.google.firebase.firestore.model.DocumentKey)

Example 18 with Target

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

the class LocalSerializerTest method testEncodesQuery.

@Test
public void testEncodesQuery() {
    Target target = new Target(path("room"), /* collectionGroup= */
    null, Collections.emptyList(), Collections.emptyList(), Target.NO_LIMIT, /* startAt= */
    null, /* endAt= */
    null);
    BundledQuery bundledQuery = new BundledQuery(target, Query.LimitType.LIMIT_TO_FIRST);
    com.google.firestore.bundle.BundledQuery encodedBundledQuery = serializer.encodeBundledQuery(bundledQuery);
    BundledQuery decodedBundledQuery = serializer.decodeBundledQuery(encodedBundledQuery);
    assertEquals(bundledQuery, decodedBundledQuery);
}
Also used : Target(com.google.firebase.firestore.core.Target) BundledQuery(com.google.firebase.firestore.bundle.BundledQuery) Test(org.junit.Test)

Example 19 with Target

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

the class LocalStoreTestCase method testHandlesSavingAndLoadingLimitToLastQueries.

@Test
public void testHandlesSavingAndLoadingLimitToLastQueries() {
    Target target = query("foo").orderBy(orderBy("foo")).limitToFirst(// Use `limitToFirst` so toTarget() does not flip ordering constraint
    5).toTarget();
    NamedQuery namedQuery = new NamedQuery("testQuery", new BundledQuery(target, Query.LimitType.LIMIT_TO_LAST), SnapshotVersion.NONE);
    saveNamedQuery(namedQuery);
    assertHasNamedQuery(namedQuery);
}
Also used : Target(com.google.firebase.firestore.core.Target) BundledQuery(com.google.firebase.firestore.bundle.BundledQuery) NamedQuery(com.google.firebase.firestore.bundle.NamedQuery) Test(org.junit.Test)

Example 20 with Target

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

the class BundleCacheTestCase method testReturnsSavedCollectionGroupQueries.

@Test
public void testReturnsSavedCollectionGroupQueries() {
    Target target = new Target(ResourcePath.EMPTY, /* collectionGroup= */
    "collectionGroup", Collections.emptyList(), Collections.emptyList(), /* limit= */
    1, /* startAt= */
    null, /* endAt= */
    null);
    BundledQuery bundledQuery = new BundledQuery(target, Query.LimitType.LIMIT_TO_FIRST);
    NamedQuery expectedQuery = new NamedQuery("query-1", bundledQuery, new SnapshotVersion(Timestamp.now()));
    bundleCache.saveNamedQuery(expectedQuery);
    NamedQuery actualQuery = bundleCache.getNamedQuery("query-1");
    assertEquals(expectedQuery, actualQuery);
}
Also used : Target(com.google.firebase.firestore.core.Target) SnapshotVersion(com.google.firebase.firestore.model.SnapshotVersion) BundledQuery(com.google.firebase.firestore.bundle.BundledQuery) NamedQuery(com.google.firebase.firestore.bundle.NamedQuery) Test(org.junit.Test)

Aggregations

Target (com.google.firebase.firestore.core.Target)23 Test (org.junit.Test)14 BundledQuery (com.google.firebase.firestore.bundle.BundledQuery)11 NamedQuery (com.google.firebase.firestore.bundle.NamedQuery)8 SnapshotVersion (com.google.firebase.firestore.model.SnapshotVersion)7 DocumentKey (com.google.firebase.firestore.model.DocumentKey)5 Filter (com.google.firebase.firestore.core.Filter)3 Query (com.google.firebase.firestore.core.Query)3 ArrayList (java.util.ArrayList)3 Nullable (androidx.annotation.Nullable)2 Bound (com.google.firebase.firestore.core.Bound)2 FieldFilter (com.google.firebase.firestore.core.FieldFilter)2 FieldIndex (com.google.firebase.firestore.model.FieldIndex)2 ByteString (com.google.protobuf.ByteString)2 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)1 User (com.google.firebase.firestore.auth.User)1 CompositeFilter (com.google.firebase.firestore.core.CompositeFilter)1 OrderBy (com.google.firebase.firestore.core.OrderBy)1 LimitType (com.google.firebase.firestore.core.Query.LimitType)1 TargetData (com.google.firebase.firestore.local.TargetData)1