18
18
import static com .google .firebase .firestore .model .FieldIndex .Segment .*;
19
19
import static com .google .firebase .firestore .testutil .TestUtil .doc ;
20
20
import static com .google .firebase .firestore .testutil .TestUtil .docMap ;
21
+ import static com .google .firebase .firestore .testutil .TestUtil .docSet ;
21
22
import static com .google .firebase .firestore .testutil .TestUtil .fieldIndex ;
22
23
import static com .google .firebase .firestore .testutil .TestUtil .filter ;
23
24
import static com .google .firebase .firestore .testutil .TestUtil .map ;
24
25
import static com .google .firebase .firestore .testutil .TestUtil .query ;
25
26
import static com .google .firebase .firestore .testutil .TestUtil .setMutation ;
26
- import static org .junit .Assert .assertTrue ;
27
+ import static org .junit .Assert .assertEquals ;
27
28
28
- import com .google .firebase .database .collection .ImmutableSortedMap ;
29
29
import com .google .firebase .firestore .core .Query ;
30
- import com .google .firebase .firestore .model .Document ;
31
- import com .google .firebase .firestore .model .DocumentKey ;
30
+ import com .google .firebase .firestore .model .DocumentSet ;
32
31
import com .google .firebase .firestore .model .MutableDocument ;
33
32
import com .google .firebase .firestore .model .SnapshotVersion ;
33
+ import org .junit .Ignore ;
34
34
import org .junit .Test ;
35
35
import org .junit .runner .RunWith ;
36
36
import org .robolectric .RobolectricTestRunner ;
@@ -50,7 +50,7 @@ public void combinesIndexedWithNonIndexedResults() throws Exception {
50
50
MutableDocument doc1 = doc ("coll/a" , 1 , map ("foo" , true ));
51
51
MutableDocument doc2 = doc ("coll/b" , 2 , map ("foo" , true ));
52
52
MutableDocument doc3 = doc ("coll/c" , 3 , map ("foo" , true ));
53
- MutableDocument doc4 = doc ("coll/d" , 3 , map ("foo" , true ));
53
+ MutableDocument doc4 = doc ("coll/d" , 3 , map ("foo" , true )). setHasLocalMutations () ;
54
54
55
55
indexManager .addFieldIndex (fieldIndex ("coll" , "foo" , Kind .ASCENDING ));
56
56
@@ -63,15 +63,29 @@ public void combinesIndexedWithNonIndexedResults() throws Exception {
63
63
addMutation (setMutation ("coll/d" , map ("foo" , true )));
64
64
65
65
Query queryWithFilter = query ("coll" ).filter (filter ("foo" , "==" , true ));
66
- ImmutableSortedMap <DocumentKey , Document > results =
67
- expectOptimizedCollectionScan (
68
- () ->
69
- queryEngine .getDocumentsMatchingQuery (
70
- queryWithFilter , SnapshotVersion .NONE , DocumentKey .emptyKeySet ()));
66
+ DocumentSet results =
67
+ expectOptimizedCollectionScan (() -> runQuery (queryWithFilter , SnapshotVersion .NONE ));
71
68
72
- assertTrue (results .containsKey (doc1 .getKey ()));
73
- assertTrue (results .containsKey (doc2 .getKey ()));
74
- assertTrue (results .containsKey (doc3 .getKey ()));
75
- assertTrue (results .containsKey (doc4 .getKey ()));
69
+ assertEquals (docSet (queryWithFilter .comparator (), doc1 , doc2 , doc3 , doc4 ), results );
70
+ }
71
+
72
+ @ Test
73
+ @ Ignore ("b/226360573" )
74
+ public void usesPartialIndexForLimitQueries () throws Exception {
75
+ MutableDocument doc1 = doc ("coll/1" , 1 , map ("a" , 1 , "b" , 0 ));
76
+ MutableDocument doc2 = doc ("coll/2" , 1 , map ("a" , 1 , "b" , 1 ));
77
+ MutableDocument doc3 = doc ("coll/3" , 1 , map ("a" , 1 , "b" , 2 ));
78
+ MutableDocument doc4 = doc ("coll/4" , 1 , map ("a" , 1 , "b" , 3 ));
79
+ MutableDocument doc5 = doc ("coll/5" , 1 , map ("a" , 2 , "b" , 3 ));
80
+ addDocument (doc1 , doc2 , doc3 , doc4 , doc5 );
81
+
82
+ indexManager .addFieldIndex (fieldIndex ("coll" , "a" , Kind .ASCENDING ));
83
+ indexManager .updateIndexEntries (docMap (doc1 , doc2 , doc3 , doc4 , doc5 ));
84
+ indexManager .updateCollectionGroup ("coll" , IndexOffset .fromDocument (doc5 ));
85
+
86
+ Query query =
87
+ query ("coll" ).filter (filter ("a" , "==" , 1 )).filter (filter ("b" , "==" , 1 )).limitToFirst (3 );
88
+ DocumentSet result = expectOptimizedCollectionScan (() -> runQuery (query , SnapshotVersion .NONE ));
89
+ assertEquals (docSet (query .comparator (), doc1 ), result );
76
90
}
77
91
}
0 commit comments