use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.
the class RemoteSerializerTest method unaryFilterTest.
private void unaryFilterTest(String op, Object equalityValue, UnaryFilter.Operator unaryOperator) {
Query q = Query.atPath(ResourcePath.fromString("docs")).filter(filter("prop", op, equalityValue));
Target actual = serializer.encodeTarget(wrapTargetData(q));
StructuredQuery.Builder structuredQueryBuilder = StructuredQuery.newBuilder().addFrom(CollectionSelector.newBuilder().setCollectionId("docs")).setWhere(Filter.newBuilder().setUnaryFilter(UnaryFilter.newBuilder().setField(FieldReference.newBuilder().setFieldPath("prop")).setOp(unaryOperator)));
// Add extra ORDER_BY field for '!=' since it is an inequality.
if (op.equals("!=")) {
structuredQueryBuilder.addOrderBy(Order.newBuilder().setDirection(Direction.ASCENDING).setField(FieldReference.newBuilder().setFieldPath("prop")));
}
structuredQueryBuilder.addOrderBy(defaultKeyOrder());
QueryTarget.Builder queryBuilder = QueryTarget.newBuilder().setParent("projects/p/databases/d/documents").setStructuredQuery(structuredQueryBuilder);
Target expected = Target.newBuilder().setQuery(queryBuilder).setTargetId(1).setResumeToken(ByteString.EMPTY).build();
assertEquals(expected, actual);
assertEquals(serializer.decodeQueryTarget(serializer.encodeQueryTarget(q.toTarget())), q.toTarget());
}
use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.
the class RemoteSerializerTest method testEncodesListenRequestLabels.
@Test
public void testEncodesListenRequestLabels() {
Query query = query("collection/key");
TargetData targetData = new TargetData(query.toTarget(), 2, 3, QueryPurpose.LISTEN);
Map<String, String> result = serializer.encodeListenRequestLabels(targetData);
assertNull(result);
targetData = new TargetData(query.toTarget(), 2, 3, QueryPurpose.LIMBO_RESOLUTION);
result = serializer.encodeListenRequestLabels(targetData);
assertEquals(map("goog-listen-tags", "limbo-document"), result);
targetData = new TargetData(query.toTarget(), 2, 3, QueryPurpose.EXISTENCE_FILTER_MISMATCH);
result = serializer.encodeListenRequestLabels(targetData);
assertEquals(map("goog-listen-tags", "existence-filter-mismatch"), result);
}
use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.
the class TargetIndexMatcherTest method withMultipleOrderBys.
@Test
public void withMultipleOrderBys() {
Query q = query("collId").orderBy(orderBy("fff")).orderBy(orderBy("bar", "desc")).orderBy(orderBy("__name__"));
validateServesTarget(q, "fff", FieldIndex.Segment.Kind.ASCENDING, "bar", FieldIndex.Segment.Kind.DESCENDING, "__name__", FieldIndex.Segment.Kind.ASCENDING);
validateDoesNotServeTarget(q, "fff", FieldIndex.Segment.Kind.ASCENDING, "__name__", FieldIndex.Segment.Kind.ASCENDING, "bar", FieldIndex.Segment.Kind.DESCENDING);
q = query("collId").orderBy(orderBy("foo")).orderBy(orderBy("bar")).orderBy(orderBy("__name__", "desc"));
validateServesTarget(q, "foo", FieldIndex.Segment.Kind.ASCENDING, "bar", FieldIndex.Segment.Kind.ASCENDING, "__name__", FieldIndex.Segment.Kind.DESCENDING);
validateDoesNotServeTarget(q, "foo", FieldIndex.Segment.Kind.ASCENDING, "__name__", FieldIndex.Segment.Kind.DESCENDING, "bar", FieldIndex.Segment.Kind.ASCENDING);
}
use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.
the class TargetIndexMatcherTest method withEqualityAndDescendingOrder.
@Test
public void withEqualityAndDescendingOrder() {
Query q = query("collId").filter(filter("a", "==", 1)).orderBy(orderBy("__name__", "desc"));
validateServesTarget(q, "a", FieldIndex.Segment.Kind.ASCENDING, "__name__", FieldIndex.Segment.Kind.DESCENDING);
}
use of com.google.firebase.firestore.core.Query in project firebase-android-sdk by firebase.
the class TargetIndexMatcherTest method withInAndOrderBy.
@Test
public void withInAndOrderBy() {
Query q = query("collId").filter(filter("a", "not-in", Arrays.asList(1, 2, 3))).orderBy(orderBy("a")).orderBy(orderBy("b"));
validateServesTarget(q, "a", FieldIndex.Segment.Kind.ASCENDING, "b", FieldIndex.Segment.Kind.ASCENDING);
}
Aggregations