use of com.google.firebase.firestore.model.FieldIndex in project firebase-android-sdk by firebase.
the class SQLiteIndexManager method encodeDirectionalElements.
/**
* Returns the byte encoded form of the directional values in the field index. Returns {@code
* null} if the document does not have all fields specified in the index.
*/
@Nullable
private byte[] encodeDirectionalElements(FieldIndex fieldIndex, Document document) {
IndexByteEncoder encoder = new IndexByteEncoder();
for (FieldIndex.Segment segment : fieldIndex.getDirectionalSegments()) {
Value field = document.getField(segment.getFieldPath());
if (field == null) {
return null;
}
DirectionalIndexByteEncoder directionalEncoder = encoder.forKind(segment.getKind());
FirestoreIndexValueWriter.INSTANCE.writeIndexValue(field, directionalEncoder);
}
return encoder.getEncodedBytes();
}
use of com.google.firebase.firestore.model.FieldIndex in project firebase-android-sdk by firebase.
the class SQLiteIndexManager method updateIndexEntries.
@Override
public void updateIndexEntries(ImmutableSortedMap<DocumentKey, Document> documents) {
hardAssert(started, "IndexManager not started");
for (Map.Entry<DocumentKey, Document> entry : documents) {
Collection<FieldIndex> fieldIndexes = getFieldIndexes(entry.getKey().getCollectionGroup());
for (FieldIndex fieldIndex : fieldIndexes) {
SortedSet<IndexEntry> existingEntries = getExistingIndexEntries(entry.getKey(), fieldIndex);
SortedSet<IndexEntry> newEntries = computeIndexEntries(entry.getValue(), fieldIndex);
if (!existingEntries.equals(newEntries)) {
updateEntries(entry.getValue(), existingEntries, newEntries);
}
}
}
}
use of com.google.firebase.firestore.model.FieldIndex in project firebase-android-sdk by firebase.
the class IndexBackfillerTest method testBackfillMutationsUpToDocumentLimitAndUpdatesBatchIdOnIndex.
@Test
public void testBackfillMutationsUpToDocumentLimitAndUpdatesBatchIdOnIndex() {
backfiller.setMaxDocumentsToProcess(2);
addFieldIndex("coll1", "foo");
addDoc("coll1/docA", version(10), "foo", 1);
addSetMutationsToOverlay(2, "coll1/docB");
addSetMutationsToOverlay(3, "coll1/docC");
addSetMutationsToOverlay(4, "coll1/docD");
int documentsProcessed = backfiller.backfill();
assertEquals(2, documentsProcessed);
verifyQueryResults("coll1", "coll1/docA", "coll1/docB");
FieldIndex fieldIndex = indexManager.getFieldIndexes("coll1").iterator().next();
assertEquals(2, fieldIndex.getIndexState().getOffset().getLargestBatchId());
documentsProcessed = backfiller.backfill();
assertEquals(2, documentsProcessed);
verifyQueryResults("coll1", "coll1/docA", "coll1/docB", "coll1/docC", "coll1/docD");
fieldIndex = indexManager.getFieldIndexes("coll1").iterator().next();
assertEquals(4, fieldIndex.getIndexState().getOffset().getLargestBatchId());
}
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) {
FieldIndex fieldIndex = fieldIndex(collectionGroup, fieldName, FieldIndex.Segment.Kind.ASCENDING);
indexManager.addFieldIndex(fieldIndex);
}
use of com.google.firebase.firestore.model.FieldIndex in project firebase-android-sdk by firebase.
the class TargetTest method partialIndexMatchQueryBound.
@Test
public void partialIndexMatchQueryBound() {
Target target = query("c").filter(filter("a", "==", "a")).filter(filter("b", "==", "b")).toTarget();
FieldIndex index = fieldIndex("c", "a", FieldIndex.Segment.Kind.ASCENDING);
Bound lowerBound = target.getLowerBound(index);
verifyBound(lowerBound, true, "a");
Bound upperBound = target.getUpperBound(index);
verifyBound(upperBound, true, "a");
}
Aggregations