19
19
import static com .google .firebase .firestore .Filter .equalTo ;
20
20
import static com .google .firebase .firestore .Filter .greaterThan ;
21
21
import static com .google .firebase .firestore .Filter .inArray ;
22
+ import static com .google .firebase .firestore .Filter .lessThan ;
23
+ import static com .google .firebase .firestore .Filter .notEqualTo ;
22
24
import static com .google .firebase .firestore .Filter .notInArray ;
23
25
import static com .google .firebase .firestore .Filter .or ;
24
26
import static com .google .firebase .firestore .testutil .Assert .assertThrows ;
@@ -532,41 +534,11 @@ public void queryOrderByKeyBoundsMustBeStringsWithoutSlashes() {
532
534
+ "document path, but 'foo' is not because it contains an odd number of segments." );
533
535
}
534
536
535
- @ Test
536
- public void queriesWithDifferentInequalityFieldsFail () {
537
- expectError (
538
- () -> testCollection ().whereGreaterThan ("x" , 32 ).whereLessThan ("y" , "cat" ),
539
- "All where filters with an inequality (notEqualTo, notIn, lessThan, "
540
- + "lessThanOrEqualTo, greaterThan, or greaterThanOrEqualTo) must be on the "
541
- + "same field. But you have filters on 'x' and 'y'" );
542
- }
543
-
544
- @ Test
545
- public void queriesWithInequalityDifferentThanFirstOrderByFail () {
546
- CollectionReference collection = testCollection ();
547
- String reason =
548
- "Invalid query. You have an inequality where filter (whereLessThan(), "
549
- + "whereGreaterThan(), etc.) on field 'x' and so you must also have 'x' as "
550
- + "your first orderBy() field, but your first orderBy() is currently on field 'y' "
551
- + "instead." ;
552
- expectError (() -> collection .whereGreaterThan ("x" , 32 ).orderBy ("y" ), reason );
553
- expectError (() -> collection .orderBy ("y" ).whereGreaterThan ("x" , 32 ), reason );
554
- expectError (() -> collection .whereGreaterThan ("x" , 32 ).orderBy ("y" ).orderBy ("x" ), reason );
555
- expectError (() -> collection .orderBy ("y" ).orderBy ("x" ).whereGreaterThan ("x" , 32 ), reason );
556
- expectError (() -> collection .orderBy ("y" ).orderBy ("x" ).whereNotEqualTo ("x" , 32 ), reason );
557
- }
558
-
559
537
@ Test
560
538
public void queriesWithMultipleNotEqualAndInequalitiesFail () {
561
539
expectError (
562
540
() -> testCollection ().whereNotEqualTo ("x" , 32 ).whereNotEqualTo ("x" , 33 ),
563
541
"Invalid Query. You cannot use more than one '!=' filter." );
564
-
565
- expectError (
566
- () -> testCollection ().whereNotEqualTo ("x" , 32 ).whereGreaterThan ("y" , 33 ),
567
- "All where filters with an inequality (notEqualTo, notIn, lessThan, "
568
- + "lessThanOrEqualTo, greaterThan, or greaterThanOrEqualTo) must be on the "
569
- + "same field. But you have filters on 'x' and 'y'" );
570
542
}
571
543
572
544
@ Test
@@ -584,9 +556,7 @@ public void queriesWithNotEqualAndNotInFiltersFail() {
584
556
public void queriesWithMultipleDisjunctiveFiltersFail () {
585
557
expectError (
586
558
() -> testCollection ().whereNotIn ("foo" , asList (1 , 2 )).whereNotIn ("bar" , asList (1 , 2 )),
587
- "All where filters with an inequality (notEqualTo, notIn, lessThan, "
588
- + "lessThanOrEqualTo, greaterThan, or greaterThanOrEqualTo) must be on the "
589
- + "same field. But you have filters on 'foo' and 'bar'" );
559
+ "Invalid Query. You cannot use more than one 'not_in' filter." );
590
560
591
561
expectError (
592
562
() ->
@@ -707,37 +677,71 @@ public void queriesUsingInAndDocumentIdMustHaveProperDocumentReferencesInArray()
707
677
}
708
678
709
679
@ Test
710
- public void testInvalidQueryFilters () {
680
+ public void testConflictingOperatorsInCompositeFilters () {
711
681
CollectionReference collection = testCollection ();
682
+ // Composite queries can validate conflicting operators in multiple inequality.
683
+ String reason = "Invalid Query. You cannot use more than one '!=' filter." ;
684
+ expectError (
685
+ () ->
686
+ collection
687
+ .where (
688
+ or (
689
+ and (lessThan ("a" , "b" ), inArray ("c" , Arrays .asList ("d" , "e" ))),
690
+ and (equalTo ("e" , "f" ), notEqualTo ("g" , "h" ))))
691
+ .where (
692
+ or (
693
+ and (greaterThan ("i" , "j" ), greaterThan ("k" , "l" )),
694
+ and (notEqualTo ("o" , "p" ), lessThan ("q" , "r" )))),
695
+ reason );
712
696
713
- // Multiple inequalities, one of which is inside a nested composite filter.
714
- String reason =
715
- "All where filters with an inequality (notEqualTo, notIn, lessThan, lessThanOrEqualTo, greaterThan, or greaterThanOrEqualTo) must be on the same field. But you have filters on 'c' and 'r'" ;
697
+ reason = "Invalid Query. You cannot use more than one 'not_in' filter." ;
716
698
expectError (
717
699
() ->
718
700
collection
719
701
.where (
720
702
or (
721
- and (equalTo ("a" , "b" ), greaterThan ("c" , "d" )),
722
- and (equalTo ("e" , "f" ), equalTo ("g" , "h" ))))
723
- .where (greaterThan ("r" , "s" )),
703
+ and (lessThan ("a" , "b" ), notInArray ("c" , Arrays .asList ("d" , "e" ))),
704
+ and (equalTo ("e" , "f" ), lessThan ("g" , "j" ))))
705
+ .where (
706
+ or (
707
+ and (greaterThan ("i" , "j" ), greaterThan ("k" , "l" )),
708
+ and (notInArray ("o" , Arrays .asList ("p" , "q" )), lessThan ("q" , "r" )))),
724
709
reason );
725
710
726
- // OrderBy and inequality on different fields. Inequality inside a nested composite filter.
727
- reason =
728
- "Invalid query. You have an inequality where filter (whereLessThan(), whereGreaterThan(), etc.) on field 'c' and so you must also have 'c' as your first orderBy() field, but your first orderBy() is currently on field 'r' instead." ;
711
+ reason = "Invalid Query. You cannot use 'not_in' filters with '!=' filters." ;
729
712
expectError (
730
713
() ->
731
714
collection
732
715
.where (
733
716
or (
734
- and (equalTo ("a" , "b" ), greaterThan ("c" , "d" )),
735
- and (equalTo ("e" , "f" ), equalTo ("g" , "h" ))))
736
- .orderBy ("r" ),
717
+ and (lessThan ("a" , "b" ), greaterThan ("c" , "d" )),
718
+ and (equalTo ("e" , "f" ), notEqualTo ("g" , "h" ))))
719
+ .where (
720
+ or (
721
+ and (greaterThan ("i" , "j" ), greaterThan ("k" , "l" )),
722
+ and (notInArray ("o" , Arrays .asList ("p" , "q" )), lessThan ("q" , "r" )))),
737
723
reason );
738
724
739
- // Conflicting operations within a composite filter.
740
725
reason = "Invalid Query. You cannot use 'not_in' filters with 'in' filters." ;
726
+ expectError (
727
+ () ->
728
+ collection
729
+ .where (
730
+ or (
731
+ and (lessThan ("a" , "b" ), inArray ("c" , Arrays .asList ("d" , "e" ))),
732
+ and (equalTo ("e" , "f" ), lessThan ("g" , "j" ))))
733
+ .where (
734
+ or (
735
+ and (greaterThan ("i" , "j" ), greaterThan ("k" , "l" )),
736
+ and (notInArray ("o" , Arrays .asList ("p" , "q" )), lessThan ("q" , "r" )))),
737
+ reason );
738
+ }
739
+
740
+ @ Test
741
+ public void testInvalidQueryFilters () {
742
+ CollectionReference collection = testCollection ();
743
+ // Conflicting operations within a composite filter.
744
+ String reason = "Invalid Query. You cannot use 'not_in' filters with 'in' filters." ;
741
745
expectError (
742
746
() ->
743
747
collection .where (
0 commit comments