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, long sequenceNumber) {
FieldIndex fieldIndex = fieldIndex(collectionGroup, FieldIndex.UNKNOWN_ID, FieldIndex.IndexState.create(sequenceNumber, IndexOffset.NONE), 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 IndexBackfillerTest method testBackfillWritesLatestReadTimeToFieldIndexOnCompletion.
@Test
public void testBackfillWritesLatestReadTimeToFieldIndexOnCompletion() {
addFieldIndex("coll1", "foo");
addFieldIndex("coll2", "bar");
addDoc("coll1/docA", version(10), "foo", 1);
addDoc("coll2/docA", version(20), "bar", 1);
int documentsProcessed = backfiller.backfill();
assertEquals(2, documentsProcessed);
FieldIndex fieldIndex1 = indexManager.getFieldIndexes("coll1").iterator().next();
FieldIndex fieldIndex2 = indexManager.getFieldIndexes("coll2").iterator().next();
assertEquals(version(10), fieldIndex1.getIndexState().getOffset().getReadTime());
assertEquals(version(20), fieldIndex2.getIndexState().getOffset().getReadTime());
addDoc("coll1/docB", version(50, 10), "foo", 1);
addDoc("coll1/docC", version(50), "foo", 1);
addDoc("coll2/docB", version(60), "bar", 1);
addDoc("coll2/docC", version(60, 10), "bar", 1);
documentsProcessed = backfiller.backfill();
assertEquals(4, documentsProcessed);
fieldIndex1 = indexManager.getFieldIndexes("coll1").iterator().next();
fieldIndex2 = indexManager.getFieldIndexes("coll2").iterator().next();
assertEquals(version(50, 10), fieldIndex1.getIndexState().getOffset().getReadTime());
assertEquals(version(60, 10), fieldIndex2.getIndexState().getOffset().getReadTime());
}
use of com.google.firebase.firestore.model.FieldIndex in project firebase-android-sdk by firebase.
the class IndexBackfillerTest method testBackfillDoesNotProcessSameDocumentTwice.
@Test
public void testBackfillDoesNotProcessSameDocumentTwice() {
addFieldIndex("coll", "foo");
addDoc("coll/doc", version(5), "foo", 1);
addSetMutationsToOverlay(1, "coll/doc");
int documentsProcessed = backfiller.backfill();
assertEquals(1, documentsProcessed);
FieldIndex fieldIndex = indexManager.getFieldIndexes("coll").iterator().next();
assertEquals(version(5), fieldIndex.getIndexState().getOffset().getReadTime());
assertEquals(1, fieldIndex.getIndexState().getOffset().getLargestBatchId());
}
use of com.google.firebase.firestore.model.FieldIndex in project firebase-android-sdk by firebase.
the class FirebaseFirestore method setIndexConfiguration.
/**
* Configures indexing for local query execution. Any previous index configuration is overridden.
* The Task resolves once the index configuration has been persisted.
*
* <p>The index entries themselves are created asynchronously. You can continue to use queries
* that require indexing even if the indices are not yet available. Query execution will
* automatically start using the index once the index entries have been written.
*
* <p>The method accepts the JSON format exported by the Firebase CLI (`firebase
* firestore:indexes`). If the JSON format is invalid, this method throws an exception.
*
* @param json The JSON format exported by the Firebase CLI.
* @return A task that resolves once all indices are successfully configured.
* @throws IllegalArgumentException if the JSON format is invalid
*/
@VisibleForTesting
Task<Void> setIndexConfiguration(String json) {
ensureClientConfigured();
Preconditions.checkState(settings.isPersistenceEnabled(), "Cannot enable indexes when persistence is disabled");
List<FieldIndex> parsedIndexes = new ArrayList<>();
try {
JSONObject jsonObject = new JSONObject(json);
if (jsonObject.has("indexes")) {
JSONArray indexes = jsonObject.getJSONArray("indexes");
for (int i = 0; i < indexes.length(); ++i) {
JSONObject definition = indexes.getJSONObject(i);
String collectionGroup = definition.getString("collectionGroup");
List<FieldIndex.Segment> segments = new ArrayList<>();
JSONArray fields = definition.optJSONArray("fields");
for (int f = 0; fields != null && f < fields.length(); ++f) {
JSONObject field = fields.getJSONObject(f);
FieldPath fieldPath = FieldPath.fromServerFormat(field.getString("fieldPath"));
if ("CONTAINS".equals(field.optString("arrayConfig"))) {
segments.add(FieldIndex.Segment.create(fieldPath, FieldIndex.Segment.Kind.CONTAINS));
} else if ("ASCENDING".equals(field.optString("order"))) {
segments.add(FieldIndex.Segment.create(fieldPath, FieldIndex.Segment.Kind.ASCENDING));
} else {
segments.add(FieldIndex.Segment.create(fieldPath, FieldIndex.Segment.Kind.DESCENDING));
}
}
parsedIndexes.add(FieldIndex.create(FieldIndex.UNKNOWN_ID, collectionGroup, segments, FieldIndex.INITIAL_STATE));
}
}
} catch (JSONException e) {
throw new IllegalArgumentException("Failed to parse index configuration", e);
}
return client.configureFieldIndexes(parsedIndexes);
}
use of com.google.firebase.firestore.model.FieldIndex in project firebase-android-sdk by firebase.
the class TargetTest method emptyQueryBound.
@Test
public void emptyQueryBound() {
Target target = query("c").toTarget();
FieldIndex index = fieldIndex("c");
Bound lowerBound = target.getLowerBound(index);
verifyBound(lowerBound, true);
Bound upperBound = target.getUpperBound(index);
verifyBound(upperBound, true);
}
Aggregations