Skip to content

Commit 20f9e56

Browse files
authored
Merge 6cbe529 into 439ba28
2 parents 439ba28 + 6cbe529 commit 20f9e56

File tree

7 files changed

+94
-163
lines changed

7 files changed

+94
-163
lines changed

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/ValidationTest.java

Lines changed: 1 addition & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -676,134 +676,9 @@ public void queriesUsingInAndDocumentIdMustHaveProperDocumentReferencesInArray()
676676
reason);
677677
}
678678

679-
// Multiple Inequality
680679
@Test
681-
public void multipleInequalityQueriesCanHaveDifferentFields() {
682-
assertDoesNotThrow(() -> testCollection().whereGreaterThan("x", 32).whereLessThan("y", "cat"));
683-
}
684-
685-
@Test
686-
public void multipleInequalityQueriesCanHaveDocumentKeyOnInequalityFields() {
687-
assertDoesNotThrow(
688-
() ->
689-
testCollection().whereGreaterThan("x", 32).whereLessThan(FieldPath.documentId(), "aa"));
690-
}
691-
692-
@Test
693-
public void multipleInequalityQueriesWithInWorks() {
694-
assertDoesNotThrow(
695-
() ->
696-
testCollection()
697-
.whereGreaterThan("x", 32)
698-
.whereLessThan("y", "cat")
699-
.whereIn("foo", asList(1, 2)));
700-
}
701-
702-
@Test
703-
public void multipleInequalityQueriesWithNotInWorks() {
704-
assertDoesNotThrow(
705-
() ->
706-
testCollection()
707-
.whereGreaterThan("x", 32)
708-
.whereLessThan("y", "cat")
709-
.whereNotIn("foo", asList(1, 2)));
710-
}
711-
712-
@Test
713-
public void multipleInequalityQueriesWithArrayContainsWorks() {
714-
assertDoesNotThrow(
715-
() ->
716-
testCollection()
717-
.whereGreaterThan("x", 32)
718-
.whereLessThan("y", "cat")
719-
.whereArrayContains("foo", 1));
720-
}
721-
722-
@Test
723-
public void multipleInequalityQueriesWithArrayContainsAnyWorks() {
724-
assertDoesNotThrow(
725-
() ->
726-
testCollection()
727-
.whereGreaterThan("x", 32)
728-
.whereLessThan("y", "cat")
729-
.whereArrayContainsAny("foo", asList(1, 2)));
730-
}
731-
732-
@Test
733-
public void queriesCanHaveInequalityFieldsDifferentThanFirstOrderBy() {
680+
public void testConflictingOperatorsInCompositeFilters() {
734681
CollectionReference collection = testCollection();
735-
736-
// Single Inequality
737-
assertDoesNotThrow(() -> collection.whereGreaterThan("x", 32).orderBy("y"));
738-
assertDoesNotThrow(() -> collection.orderBy("y").whereGreaterThan("x", 32));
739-
assertDoesNotThrow(() -> collection.whereGreaterThan("x", 32).orderBy("y").orderBy("x"));
740-
assertDoesNotThrow(() -> collection.orderBy("y").orderBy("x").whereGreaterThan("x", 32));
741-
assertDoesNotThrow(() -> collection.orderBy("y").orderBy("x").whereNotEqualTo("x", 32));
742-
743-
// Multiple Inequality
744-
assertDoesNotThrow(
745-
() -> collection.whereGreaterThan("x", 32).whereNotEqualTo("y", "cat").orderBy("z"));
746-
assertDoesNotThrow(
747-
() -> collection.orderBy("z").whereGreaterThan("x", 32).whereNotEqualTo("y", "cat"));
748-
assertDoesNotThrow(
749-
() ->
750-
collection
751-
.whereGreaterThan("x", 32)
752-
.orderBy("z")
753-
.orderBy("x")
754-
.whereNotEqualTo("y", "cat"));
755-
assertDoesNotThrow(
756-
() ->
757-
collection
758-
.orderBy("z")
759-
.orderBy("x")
760-
.whereGreaterThan("x", 32)
761-
.whereNotEqualTo("y", "cat"));
762-
assertDoesNotThrow(
763-
() ->
764-
collection
765-
.orderBy("z")
766-
.orderBy("x")
767-
.whereNotEqualTo("y", "cat")
768-
.whereGreaterThan("x", 32));
769-
}
770-
771-
@Test
772-
public void testMultipleInequalityInCompositeFilters() {
773-
CollectionReference collection = testCollection();
774-
// Multiple inequality on different fields between a field filter and a composite filter.
775-
assertDoesNotThrow(
776-
() ->
777-
collection
778-
.where(
779-
or(
780-
and(equalTo("a", "b"), greaterThan("c", "d")),
781-
and(lessThan("e", "f"), notEqualTo("g", "h"))))
782-
.where(greaterThan("r", "s")));
783-
784-
// OrderBy and inequality on different fields. Inequality inside a nested composite filter.
785-
assertDoesNotThrow(
786-
() ->
787-
collection
788-
.where(
789-
or(
790-
and(equalTo("a", "b"), greaterThan("c", "d")),
791-
and(lessThan("e", "f"), notEqualTo("g", "h"))))
792-
.orderBy("r")
793-
.orderBy("a"));
794-
795-
// Multiple inequality on different fields between a field filter and a composite filter.
796-
assertDoesNotThrow(
797-
() ->
798-
collection.where(
799-
and(
800-
or(
801-
and(notEqualTo("a", "b"), greaterThan("c", "d")),
802-
and(lessThan("e", "f"), equalTo("g", "h"))),
803-
or(
804-
and(equalTo("i", "j"), greaterThan("k", "l")),
805-
and(lessThan("m", "n"), equalTo("o", "p"))))));
806-
807682
// Composite queries can validate conflicting operators in multiple inequality.
808683
String reason = "Invalid Query. You cannot use more than one '!=' filter.";
809684
expectError(

firebase-firestore/src/main/java/com/google/firebase/firestore/core/CompositeFilter.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,6 @@ public List<FieldFilter> getFlattenedFilters() {
7373
return Collections.unmodifiableList(memoizedFlattenedFilters);
7474
}
7575

76-
/**
77-
* Performs a depth-first search to find and return the inequality FieldFilters in the composite
78-
* filter. Returns an empty array if none of the FieldFilters has inequality filters.
79-
*/
80-
@Override
81-
public List<FieldFilter> getInequalityFilters() {
82-
List<FieldFilter> flattenedFilters = getFlattenedFilters();
83-
List<FieldFilter> inequalityFilters = new ArrayList<>();
84-
85-
for (FieldFilter filter : flattenedFilters) {
86-
if (filter.isInequality()) {
87-
inequalityFilters.add(filter);
88-
}
89-
}
90-
91-
return inequalityFilters;
92-
}
93-
9476
public boolean isConjunction() {
9577
return operator == Operator.AND;
9678
}

firebase-firestore/src/main/java/com/google/firebase/firestore/core/FieldFilter.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,6 @@ public List<Filter> getFilters() {
172172
return Collections.singletonList(this);
173173
}
174174

175-
@Override
176-
public List<FieldFilter> getInequalityFilters() {
177-
/**
178-
* We return a list of size one if it is an inequality filter, otherwise return an empty list.
179-
*/
180-
if (isInequality()) {
181-
return Collections.singletonList(this);
182-
}
183-
return Collections.emptyList();
184-
}
185-
186175
@Override
187176
public String toString() {
188177
return getCanonicalId();

firebase-firestore/src/main/java/com/google/firebase/firestore/core/Filter.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,4 @@ public abstract class Filter {
2929

3030
/** Returns a list of all filters that are contained within this filter */
3131
public abstract List<Filter> getFilters();
32-
33-
/** Returns a list of all field filters that's an inequality */
34-
public abstract List<FieldFilter> getInequalityFilters();
3532
}

firebase-firestore/src/main/java/com/google/firebase/firestore/core/Query.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ public SortedSet<FieldPath> getInequalityFilterFields() {
177177
SortedSet<FieldPath> result = new TreeSet<FieldPath>();
178178

179179
for (Filter filter : getFilters()) {
180-
List<FieldFilter> inequalityFilters = filter.getInequalityFilters();
181-
for (FieldFilter inequalityFilter : inequalityFilters) {
182-
FieldPath field = inequalityFilter.getField();
183-
result.add(field);
180+
for (FieldFilter subFilter : filter.getFlattenedFilters()) {
181+
if (subFilter.isInequality()) {
182+
result.add(subFilter.getField());
183+
}
184184
}
185185
}
186186

firebase-firestore/src/test/java/com/google/firebase/firestore/core/QueryTest.java

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,94 @@ public void testImplicitOrderBy() {
615615
baseQuery.orderBy(orderBy("foo", "desc")).orderBy(orderBy("bar", "asc")).getOrderBy());
616616
}
617617

618+
@Test
619+
public void testImplicitOrderByInMultipleInequality() {
620+
Query baseQuery = Query.atPath(path("foo"));
621+
assertEquals(
622+
asList(
623+
orderBy("A", "asc"),
624+
orderBy("a", "asc"),
625+
orderBy("aa", "asc"),
626+
orderBy("b", "asc"),
627+
orderBy(KEY_FIELD_NAME, "asc")),
628+
baseQuery
629+
.filter(filter("a", "<", 5))
630+
.filter(filter("aa", "<", 5))
631+
.filter(filter("b", "<", 5))
632+
.filter(filter("A", "<", 5))
633+
.getOrderBy());
634+
635+
// numbers
636+
assertEquals(
637+
asList(
638+
orderBy("1", "asc"),
639+
orderBy("19", "asc"),
640+
orderBy("2", "asc"),
641+
orderBy("a", "asc"),
642+
orderBy(KEY_FIELD_NAME, "asc")),
643+
baseQuery
644+
.filter(filter("a", "<", 5))
645+
.filter(filter("1", "<", 5))
646+
.filter(filter("2", "<", 5))
647+
.filter(filter("19", "<", 5))
648+
.getOrderBy());
649+
650+
// nested fields
651+
assertEquals(
652+
asList(
653+
orderBy("a", "asc"),
654+
orderBy("a.a", "asc"),
655+
orderBy("aa", "asc"),
656+
orderBy(KEY_FIELD_NAME, "asc")),
657+
baseQuery
658+
.filter(filter("a", "<", 5))
659+
.filter(filter("aa", "<", 5))
660+
.filter(filter("a.a", "<", 5))
661+
.getOrderBy());
662+
663+
// special characters
664+
assertEquals(
665+
asList(
666+
orderBy("_a", "asc"),
667+
orderBy("a", "asc"),
668+
orderBy("a.a", "asc"),
669+
orderBy(KEY_FIELD_NAME, "asc")),
670+
baseQuery
671+
.filter(filter("a", "<", 5))
672+
.filter(filter("_a", "<", 5))
673+
.filter(filter("a.a", "<", 5))
674+
.getOrderBy());
675+
676+
// field name with dot
677+
assertEquals(
678+
asList(
679+
orderBy("a", "asc"),
680+
orderBy("a.z", "asc"),
681+
orderBy("`a.a`", "asc"),
682+
orderBy(KEY_FIELD_NAME, "asc")),
683+
baseQuery
684+
.filter(filter("a", "<", 5))
685+
.filter(filter("`a.a`", "<", 5)) // Field name with dot
686+
.filter(filter("a.z", "<", 5)) // Nested field
687+
.getOrderBy());
688+
689+
// composite filter
690+
assertEquals(
691+
asList(
692+
orderBy("a", "asc"),
693+
orderBy("b", "asc"),
694+
orderBy("c", "asc"),
695+
orderBy("d", "asc"),
696+
orderBy(KEY_FIELD_NAME, "asc")),
697+
baseQuery
698+
.filter(filter("a", "<", 5))
699+
.filter(
700+
andFilters(
701+
orFilters(filter("b", ">=", 1), filter("c", "<=", 1)),
702+
orFilters(filter("d", "<=", 1), filter("e", "==", 1))))
703+
.getOrderBy());
704+
}
705+
618706
@Test
619707
public void testMatchesAllDocuments() {
620708
Query baseQuery = Query.atPath(ResourcePath.fromString("collection"));

firebase-firestore/src/testUtil/java/com/google/firebase/firestore/testutil/TestUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public static Query query(String path) {
180180
}
181181

182182
public static FieldPath field(String path) {
183-
return FieldPath.fromSegments(Arrays.asList(path.split("\\.")));
183+
return FieldPath.fromServerFormat(path);
184184
}
185185

186186
public static DocumentReference ref(String key) {

0 commit comments

Comments
 (0)