use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.
the class SQLiteIndexManagerTest method testNoMatchingDocs.
@Test
public void testNoMatchingDocs() {
setUpSingleValueFilter();
Query query = query("coll").filter(filter("count", "==", -1));
verifyResults(query);
}
use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.
the class SQLiteIndexManagerTest method testLimitFilter.
@Test
public void testLimitFilter() {
indexManager.addFieldIndex(fieldIndex("coll", "value", Kind.ASCENDING));
addDoc("coll/doc1", map("value", 1));
addDoc("coll/doc2", map("value", 1));
addDoc("coll/doc3", map("value", 1));
Query query = query("coll").filter(filter("value", "==", 1)).limitToFirst(2);
verifyResults(query, "coll/doc1", "coll/doc2");
}
use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.
the class SQLiteIndexManagerTest method testAdvancedQueries.
@Test
public void testAdvancedQueries() {
// This test compares local query results with those received from the Java Server SDK.
indexManager.addFieldIndex(fieldIndex("coll", "null", Kind.ASCENDING));
indexManager.addFieldIndex(fieldIndex("coll", "int", Kind.ASCENDING));
indexManager.addFieldIndex(fieldIndex("coll", "float", Kind.ASCENDING));
indexManager.addFieldIndex(fieldIndex("coll", "string", Kind.ASCENDING));
indexManager.addFieldIndex(fieldIndex("coll", "multi", Kind.ASCENDING));
indexManager.addFieldIndex(fieldIndex("coll", "array", Kind.ASCENDING));
indexManager.addFieldIndex(fieldIndex("coll", "array", Kind.DESCENDING));
indexManager.addFieldIndex(fieldIndex("coll", "array", Kind.CONTAINS));
indexManager.addFieldIndex(fieldIndex("coll", "map", Kind.ASCENDING));
indexManager.addFieldIndex(fieldIndex("coll", "map.field", Kind.ASCENDING));
indexManager.addFieldIndex(fieldIndex("coll", "prefix", Kind.ASCENDING));
indexManager.addFieldIndex(fieldIndex("coll", "prefix", Kind.ASCENDING, "suffix", Kind.ASCENDING));
indexManager.addFieldIndex(fieldIndex("coll", "a", Kind.ASCENDING));
indexManager.addFieldIndex(fieldIndex("coll", "a", Kind.ASCENDING, "b", Kind.ASCENDING));
indexManager.addFieldIndex(fieldIndex("coll", "a", Kind.DESCENDING, "b", Kind.ASCENDING));
indexManager.addFieldIndex(fieldIndex("coll", "a", Kind.ASCENDING, "b", Kind.DESCENDING));
indexManager.addFieldIndex(fieldIndex("coll", "a", Kind.DESCENDING, "b", Kind.DESCENDING));
indexManager.addFieldIndex(fieldIndex("coll", "b", Kind.ASCENDING, "a", Kind.ASCENDING));
List<Map<String, Object>> data = new ArrayList<Map<String, Object>>() {
{
add(map());
add(map("int", 1, "array", Arrays.asList(1, "foo")));
add(map("array", Arrays.asList(2, "foo")));
add(map("int", 3, "array", Arrays.asList(3, "foo")));
add(map("array", "foo"));
add(map("array", Collections.singletonList(1)));
add(map("float", -0.0, "string", "a"));
add(map("float", 0, "string", "ab"));
add(map("float", 0.0, "string", "b"));
add(map("float", Double.NaN));
add(map("multi", true));
add(map("multi", 1));
add(map("multi", "string"));
add(map("multi", Collections.emptyList()));
add(map("null", null));
add(map("prefix", Arrays.asList(1, 2), "suffix", null));
add(map("prefix", Collections.singletonList(1), "suffix", 2));
add(map("map", map()));
add(map("map", map("field", true)));
add(map("map", map("field", false)));
add(map("a", 0, "b", 0));
add(map("a", 0, "b", 1));
add(map("a", 1, "b", 0));
add(map("a", 1, "b", 1));
add(map("a", 2, "b", 0));
add(map("a", 2, "b", 1));
}
};
for (int i = 0; i < data.size(); ++i) {
addDoc("coll/" + Values.canonicalId(wrap(data.get(i))), data.get(i));
}
Query q = query("coll");
verifyResults(q.orderBy(orderBy("int")), "coll/{array:[1,foo],int:1}", "coll/{array:[3,foo],int:3}");
verifyResults(q.filter(filter("float", "==", Double.NaN)), "coll/{float:NaN}");
verifyResults(q.filter(filter("float", "==", -0.0)), "coll/{float:-0.0,string:a}", "coll/{float:0,string:ab}", "coll/{float:0.0,string:b}");
verifyResults(q.filter(filter("float", "==", 0)), "coll/{float:-0.0,string:a}", "coll/{float:0,string:ab}", "coll/{float:0.0,string:b}");
verifyResults(q.filter(filter("float", "==", 0.0)), "coll/{float:-0.0,string:a}", "coll/{float:0,string:ab}", "coll/{float:0.0,string:b}");
verifyResults(q.filter(filter("string", "==", "a")), "coll/{float:-0.0,string:a}");
verifyResults(q.filter(filter("string", ">", "a")), "coll/{float:0,string:ab}", "coll/{float:0.0,string:b}");
verifyResults(q.filter(filter("string", ">=", "a")), "coll/{float:-0.0,string:a}", "coll/{float:0,string:ab}", "coll/{float:0.0,string:b}");
verifyResults(q.filter(filter("string", "<", "b")), "coll/{float:-0.0,string:a}", "coll/{float:0,string:ab}");
verifyResults(q.filter(filter("string", "<", "coll")), "coll/{float:-0.0,string:a}", "coll/{float:0,string:ab}", "coll/{float:0.0,string:b}");
verifyResults(q.filter(filter("string", ">", "a")).filter(filter("string", "<", "b")), "coll/{float:0,string:ab}");
verifyResults(q.filter(filter("array", "array-contains", "foo")), "coll/{array:[1,foo],int:1}", "coll/{array:[2,foo]}", "coll/{array:[3,foo],int:3}");
verifyResults(q.filter(filter("array", "array-contains-any", Arrays.asList(1, "foo"))), "coll/{array:[1,foo],int:1}", "coll/{array:[1]}", "coll/{array:[2,foo]}", "coll/{array:[3,foo],int:3}");
verifyResults(q.filter(filter("multi", ">=", true)), "coll/{multi:true}");
verifyResults(q.filter(filter("multi", ">=", 0)), "coll/{multi:1}");
verifyResults(q.filter(filter("multi", ">=", "")), "coll/{multi:string}");
verifyResults(q.filter(filter("multi", ">=", Collections.emptyList())), "coll/{multi:[]}");
verifyResults(q.filter(filter("multi", "!=", true)), "coll/{multi:1}", "coll/{multi:string}", "coll/{multi:[]}");
verifyResults(q.filter(filter("multi", "in", Arrays.asList(true, 1))), "coll/{multi:true}", "coll/{multi:1}");
verifyResults(q.filter(filter("multi", "not-in", Arrays.asList(true, 1))), "coll/{multi:string}", "coll/{multi:[]}");
verifyResults(q.orderBy(orderBy("array")).startAt(bound(true, Collections.singletonList(2))), "coll/{array:[2,foo]}", "coll/{array:[3,foo],int:3}");
verifyResults(q.orderBy(orderBy("array", "desc")).startAt(bound(true, Collections.singletonList(2))), "coll/{array:[1,foo],int:1}", "coll/{array:[1]}", "coll/{array:foo}");
verifyResults(q.orderBy(orderBy("array", "desc")).startAt(bound(true, Collections.singletonList(2))).limitToFirst(2), "coll/{array:[1,foo],int:1}", "coll/{array:[1]}");
verifyResults(q.orderBy(orderBy("array")).startAt(bound(false, Collections.singletonList(2))), "coll/{array:[2,foo]}", "coll/{array:[3,foo],int:3}");
verifyResults(q.orderBy(orderBy("array", "desc")).startAt(bound(false, Collections.singletonList(2))), "coll/{array:[1,foo],int:1}", "coll/{array:[1]}", "coll/{array:foo}");
verifyResults(q.orderBy(orderBy("array", "desc")).startAt(bound(false, Collections.singletonList(2))).limitToFirst(2), "coll/{array:[1,foo],int:1}", "coll/{array:[1]}");
verifyResults(q.orderBy(orderBy("array")).startAt(bound(false, Arrays.asList(2, "foo"))), "coll/{array:[3,foo],int:3}");
verifyResults(q.orderBy(orderBy("array", "desc")).startAt(bound(false, Arrays.asList(2, "foo"))), "coll/{array:[1,foo],int:1}", "coll/{array:[1]}", "coll/{array:foo}");
verifyResults(q.orderBy(orderBy("array", "desc")).startAt(bound(false, Arrays.asList(2, "foo"))).limitToFirst(2), "coll/{array:[1,foo],int:1}", "coll/{array:[1]}");
verifyResults(q.orderBy(orderBy("array")).endAt(bound(true, Collections.singletonList(2))), "coll/{array:foo}", "coll/{array:[1]}", "coll/{array:[1,foo],int:1}");
verifyResults(q.orderBy(orderBy("array", "desc")).endAt(bound(true, Collections.singletonList(2))), "coll/{array:[3,foo],int:3}", "coll/{array:[2,foo]}");
verifyResults(q.orderBy(orderBy("array")).endAt(bound(false, Collections.singletonList(2))), "coll/{array:foo}", "coll/{array:[1]}", "coll/{array:[1,foo],int:1}");
verifyResults(q.orderBy(orderBy("array")).endAt(bound(false, Collections.singletonList(2))).limitToFirst(2), "coll/{array:foo}", "coll/{array:[1]}");
verifyResults(q.orderBy(orderBy("array", "desc")).endAt(bound(false, Collections.singletonList(2))), "coll/{array:[3,foo],int:3}", "coll/{array:[2,foo]}");
verifyResults(q.orderBy(orderBy("array")).endAt(bound(false, Arrays.asList(2, "foo"))), "coll/{array:foo}", "coll/{array:[1]}", "coll/{array:[1,foo],int:1}");
verifyResults(q.orderBy(orderBy("array")).endAt(bound(false, Arrays.asList(2, "foo"))).limitToFirst(2), "coll/{array:foo}", "coll/{array:[1]}");
verifyResults(q.orderBy(orderBy("array", "desc")).endAt(bound(false, Arrays.asList(2, "foo"))), "coll/{array:[3,foo],int:3}");
verifyResults(q.orderBy(orderBy("a")).orderBy(orderBy("b")).limitToFirst(1), "coll/{a:0,b:0}");
verifyResults(q.orderBy(orderBy("a", "desc")).orderBy(orderBy("b")).limitToFirst(1), "coll/{a:2,b:0}");
verifyResults(q.orderBy(orderBy("a")).orderBy(orderBy("b", "desc")).limitToFirst(1), "coll/{a:0,b:1}");
verifyResults(q.orderBy(orderBy("a", "desc")).orderBy(orderBy("b", "desc")).limitToFirst(1), "coll/{a:2,b:1}");
verifyResults(q.filter(filter("a", ">", 0)).filter(filter("b", "==", 1)), "coll/{a:1,b:1}", "coll/{a:2,b:1}");
verifyResults(q.filter(filter("a", "==", 1)).filter(filter("b", "==", 1)), "coll/{a:1,b:1}");
verifyResults(q.filter(filter("a", "!=", 0)).filter(filter("b", "==", 1)), "coll/{a:1,b:1}", "coll/{a:2,b:1}");
verifyResults(q.filter(filter("b", "==", 1)).filter(filter("a", "!=", 0)), "coll/{a:1,b:1}", "coll/{a:2,b:1}");
verifyResults(q.filter(filter("a", "not-in", Arrays.asList(0, 1))), "coll/{a:2,b:0}", "coll/{a:2,b:1}");
verifyResults(q.filter(filter("a", "not-in", Arrays.asList(0, 1))).filter(filter("b", "==", 1)), "coll/{a:2,b:1}");
verifyResults(q.filter(filter("b", "==", 1)).filter(filter("a", "not-in", Arrays.asList(0, 1))), "coll/{a:2,b:1}");
verifyResults(q.filter(filter("null", "==", null)), "coll/{null:null}");
verifyResults(q.orderBy(orderBy("null")), "coll/{null:null}");
verifyResults(q.filter(filter("prefix", "==", Arrays.asList(1, 2))), "coll/{prefix:[1,2],suffix:null}");
verifyResults(q.filter(filter("prefix", "==", Collections.singletonList(1))).filter(filter("suffix", "==", 2)), "coll/{prefix:[1],suffix:2}");
verifyResults(q.filter(filter("map", "==", map())), "coll/{map:{}}");
verifyResults(q.filter(filter("map", "==", map("field", true))), "coll/{map:{field:true}}");
verifyResults(q.filter(filter("map.field", "==", true)), "coll/{map:{field:true}}");
verifyResults(q.orderBy(orderBy("map")), "coll/{map:{}}", "coll/{map:{field:false}}", "coll/{map:{field:true}}");
verifyResults(q.orderBy(orderBy("map.field")), "coll/{map:{field:false}}", "coll/{map:{field:true}}");
}
use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.
the class SQLiteIndexManagerTest method testStartAtFilter.
@Test
public void testStartAtFilter() {
setUpSingleValueFilter();
Query query = query("coll").orderBy(orderBy("count")).startAt(bound(/* inclusive= */
true, 2));
verifyResults(query, "coll/val2", "coll/val3");
}
use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.
the class SQLiteIndexManagerTest method testInFilter.
@Test
public void testInFilter() {
setUpSingleValueFilter();
Query query = query("coll").filter(filter("count", "in", Arrays.asList(1, 3)));
verifyResults(query, "coll/val1", "coll/val3");
}
Aggregations