@@ -404,6 +404,12 @@ public void queriesWithNullOrNaNFiltersOtherThanEqualityFail() {
404
404
expectError (
405
405
() -> collection .whereArrayContains ("a" , null ),
406
406
"Invalid Query. You can only perform equality comparisons on null (via whereEqualTo())." );
407
+ expectError (
408
+ () -> collection .whereArrayContainsAny ("a" , null ),
409
+ "Invalid Query. A non-empty array is required for 'array_contains_any' filters." );
410
+ expectError (
411
+ () -> collection .whereIn ("a" , null ),
412
+ "Invalid Query. A non-empty array is required for 'in' filters." );
407
413
408
414
expectError (
409
415
() -> collection .whereGreaterThan ("a" , Double .NaN ),
@@ -535,10 +541,129 @@ public void queriesWithInequalityDifferentThanFirstOrderByFail() {
535
541
}
536
542
537
543
@ Test
538
- public void queriesWithMultipleArrayContainsFiltersFail () {
544
+ public void queriesWithMultipleArrayFiltersFail () {
539
545
expectError (
540
546
() -> testCollection ().whereArrayContains ("foo" , 1 ).whereArrayContains ("foo" , 2 ),
541
- "Invalid Query. Queries only support having a single array-contains filter." );
547
+ "Invalid Query. You cannot use more than one 'array_contains' filter." );
548
+
549
+ expectError (
550
+ () ->
551
+ testCollection ()
552
+ .whereArrayContains ("foo" , 1 )
553
+ .whereArrayContainsAny ("foo" , asList (1 , 2 )),
554
+ "Invalid Query. You cannot use 'array_contains_any' filters with 'array_contains' filters." );
555
+
556
+ expectError (
557
+ () ->
558
+ testCollection ()
559
+ .whereArrayContainsAny ("foo" , asList (1 , 2 ))
560
+ .whereArrayContains ("foo" , 1 ),
561
+ "Invalid Query. You cannot use 'array_contains' filters with 'array_contains_any' filters." );
562
+ }
563
+
564
+ @ Test
565
+ public void queriesWithMultipleDisjunctiveFiltersFail () {
566
+ expectError (
567
+ () -> testCollection ().whereIn ("foo" , asList (1 , 2 )).whereIn ("bar" , asList (1 , 2 )),
568
+ "Invalid Query. You cannot use more than one 'in' filter." );
569
+
570
+ expectError (
571
+ () ->
572
+ testCollection ()
573
+ .whereArrayContainsAny ("foo" , asList (1 , 2 ))
574
+ .whereArrayContainsAny ("bar" , asList (1 , 2 )),
575
+ "Invalid Query. You cannot use more than one 'array_contains_any' filter." );
576
+
577
+ expectError (
578
+ () ->
579
+ testCollection ()
580
+ .whereArrayContainsAny ("foo" , asList (1 , 2 ))
581
+ .whereIn ("bar" , asList (1 , 2 )),
582
+ "Invalid Query. You cannot use 'in' filters with 'array_contains_any' filters." );
583
+
584
+ expectError (
585
+ () ->
586
+ testCollection ()
587
+ .whereIn ("bar" , asList (1 , 2 ))
588
+ .whereArrayContainsAny ("foo" , asList (1 , 2 )),
589
+ "Invalid Query. You cannot use 'array_contains_any' filters with 'in' filters." );
590
+
591
+ // This is redundant with the above tests, but makes sure our validation doesn't get confused.
592
+ expectError (
593
+ () ->
594
+ testCollection ()
595
+ .whereIn ("bar" , asList (1 , 2 ))
596
+ .whereArrayContains ("foo" , 1 )
597
+ .whereArrayContainsAny ("foo" , asList (1 , 2 )),
598
+ "Invalid Query. You cannot use 'array_contains_any' filters with 'in' filters." );
599
+
600
+ expectError (
601
+ () ->
602
+ testCollection ()
603
+ .whereArrayContains ("foo" , 1 )
604
+ .whereIn ("bar" , asList (1 , 2 ))
605
+ .whereArrayContainsAny ("foo" , asList (1 , 2 )),
606
+ "Invalid Query. You cannot use 'array_contains_any' filters with 'in' filters." );
607
+ }
608
+
609
+ @ Test
610
+ public void queriesCanUseInWithArrayContains () {
611
+ testCollection ().whereArrayContains ("foo" , 1 ).whereIn ("bar" , asList (1 , 2 ));
612
+ testCollection ().whereIn ("bar" , asList (1 , 2 )).whereArrayContains ("foo" , 1 );
613
+
614
+ expectError (
615
+ () ->
616
+ testCollection ()
617
+ .whereIn ("bar" , asList (1 , 2 ))
618
+ .whereArrayContains ("foo" , 1 )
619
+ .whereArrayContains ("foo" , 1 ),
620
+ "Invalid Query. You cannot use more than one 'array_contains' filter." );
621
+
622
+ expectError (
623
+ () ->
624
+ testCollection ()
625
+ .whereArrayContains ("foo" , 1 )
626
+ .whereIn ("bar" , asList (1 , 2 ))
627
+ .whereIn ("bar" , asList (1 , 2 )),
628
+ "Invalid Query. You cannot use more than one 'in' filter." );
629
+ }
630
+
631
+ @ Test
632
+ public void queriesInAndArrayContainsAnyArrayRules () {
633
+ expectError (
634
+ () -> testCollection ().whereIn ("bar" , asList ()),
635
+ "Invalid Query. A non-empty array is required for 'in' filters." );
636
+
637
+ expectError (
638
+ () -> testCollection ().whereArrayContainsAny ("bar" , asList ()),
639
+ "Invalid Query. A non-empty array is required for 'array_contains_any' filters." );
640
+
641
+ expectError (
642
+ // The 10 element max includes duplicates.
643
+ () -> testCollection ().whereIn ("bar" , asList (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 9 , 9 )),
644
+ "Invalid Query. 'in' filters support a maximum of 10 elements in the value array." );
645
+
646
+ expectError (
647
+ // The 10 element max includes duplicates.
648
+ () ->
649
+ testCollection ().whereArrayContainsAny ("bar" , asList (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 9 , 9 )),
650
+ "Invalid Query. 'array_contains_any' filters support a maximum of 10 elements in the value array." );
651
+
652
+ expectError (
653
+ () -> testCollection ().whereIn ("bar" , asList ("foo" , null )),
654
+ "Invalid Query. 'in' filters cannot contain 'null' in the value array." );
655
+
656
+ expectError (
657
+ () -> testCollection ().whereArrayContainsAny ("bar" , asList ("foo" , null )),
658
+ "Invalid Query. 'array_contains_any' filters cannot contain 'null' in the value array." );
659
+
660
+ expectError (
661
+ () -> testCollection ().whereIn ("bar" , asList ("foo" , Double .NaN )),
662
+ "Invalid Query. 'in' filters cannot contain 'NaN' in the value array." );
663
+
664
+ expectError (
665
+ () -> testCollection ().whereArrayContainsAny ("bar" , asList ("foo" , Float .NaN )),
666
+ "Invalid Query. 'array_contains_any' filters cannot contain 'NaN' in the value array." );
542
667
}
543
668
544
669
@ Test
@@ -576,6 +701,11 @@ public void queriesFilteredByDocumentIDMustUseStringsOrDocumentReferences() {
576
701
+ "a valid String or DocumentReference, but it was of type: java.lang.Integer" ;
577
702
expectError (() -> collection .whereGreaterThanOrEqualTo (FieldPath .documentId (), 1 ), reason );
578
703
704
+ reason =
705
+ "Invalid query. When querying with FieldPath.documentId() you must provide "
706
+ + "a valid String or DocumentReference, but it was of type: java.util.Arrays$ArrayList" ;
707
+ expectError (() -> collection .whereIn (FieldPath .documentId (), asList (1 , 2 )), reason );
708
+
579
709
reason =
580
710
"Invalid query. When querying a collection group by FieldPath.documentId(), the value "
581
711
+ "provided must result in a valid document path, but 'foo' is not because it has "
@@ -587,10 +717,13 @@ public void queriesFilteredByDocumentIDMustUseStringsOrDocumentReferences() {
587
717
.whereGreaterThanOrEqualTo (FieldPath .documentId (), "foo" ),
588
718
reason );
589
719
590
- reason =
591
- "Invalid query. You can't perform array-contains queries on FieldPath.documentId() since "
592
- + "document IDs are not arrays." ;
720
+ reason = "Invalid query. You can't perform 'array_contains' queries on FieldPath.documentId()." ;
593
721
expectError (() -> collection .whereArrayContains (FieldPath .documentId (), 1 ), reason );
722
+
723
+ reason =
724
+ "Invalid query. You can't perform 'array_contains_any' queries on FieldPath.documentId()." ;
725
+ expectError (
726
+ () -> collection .whereArrayContainsAny (FieldPath .documentId (), asList (1 , 2 )), reason );
594
727
}
595
728
596
729
// Helpers
0 commit comments