Skip to content

Commit 441d7ed

Browse files
author
Brian Chen
authored
Change id to NSArray<id> for IN queries (#4182)
1 parent fb441a0 commit 441d7ed

File tree

4 files changed

+12
-20
lines changed

4 files changed

+12
-20
lines changed

Firestore/Example/Tests/Integration/API/FIRValidationTests.mm

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,6 @@ - (void)testNonEqualityQueriesOnNullOrNaNFail {
414414
@"Invalid Query. Null supports only equality comparisons.");
415415
FSTAssertThrows([[self collectionRef] queryWhereField:@"a" arrayContains:[NSNull null]],
416416
@"Invalid Query. Null supports only equality comparisons.");
417-
FSTAssertThrows([[self collectionRef] queryWhereField:@"a" arrayContainsAny:[NSNull null]],
418-
@"Invalid Query. A non-empty array is required for 'arrayContainsAny' filters.");
419-
FSTAssertThrows([[self collectionRef] queryWhereField:@"a" arrayContainsAny:[NSNull null]],
420-
@"Invalid Query. A non-empty array is required for 'arrayContainsAny' filters.");
421417

422418
FSTAssertThrows([[self collectionRef] queryWhereField:@"a" isGreaterThan:@(NAN)],
423419
@"Invalid Query. NaN supports only equality comparisons.");
@@ -558,12 +554,6 @@ - (void)testQueriesFilteredByDocumentIdMustUseStringsOrDocumentReferences {
558554
"are not arrays.";
559555
FSTAssertThrows([collection queryWhereFieldPath:[FIRFieldPath documentID] arrayContains:@1],
560556
reason);
561-
562-
reason = @"Invalid query. You can't perform arrayContainsAny queries on document ID since "
563-
@"document IDs "
564-
"are not arrays.";
565-
FSTAssertThrows([collection queryWhereFieldPath:[FIRFieldPath documentID] arrayContainsAny:@1],
566-
reason);
567557
}
568558

569559
- (void)testQueriesUsingInAndDocumentIdMustHaveProperDocumentReferencesInArray {

Firestore/Source/API/FIRQuery+Internal.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ NS_ASSUME_NONNULL_BEGIN
5656
* @return The created `FIRQuery`.
5757
*/
5858
// TODO(b/138855186): Expose to public once backend is ready.
59-
- (FIRQuery *)queryWhereField:(NSString *)field arrayContainsAny:(id)value;
59+
- (FIRQuery *)queryWhereField:(NSString *)field arrayContainsAny:(NSArray<id> *)value;
6060

6161
/**
6262
* Creates and returns a new `FIRQuery` with the additional filter that documents must contain
@@ -72,7 +72,7 @@ NS_ASSUME_NONNULL_BEGIN
7272
* @return The created `FIRQuery`.
7373
*/
7474
// TODO(b/138855186): Expose to public once backend is ready.
75-
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path arrayContainsAny:(id)value;
75+
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path arrayContainsAny:(NSArray<id> *)value;
7676

7777
/**
7878
* Creates and returns a new `FIRQuery` with the additional filter that documents must contain
@@ -86,7 +86,7 @@ NS_ASSUME_NONNULL_BEGIN
8686
* @return The created `FIRQuery`.
8787
*/
8888
// TODO(b/138855186): Expose to public once backend is ready.
89-
- (FIRQuery *)queryWhereField:(NSString *)field in:(id)value;
89+
- (FIRQuery *)queryWhereField:(NSString *)field in:(NSArray<id> *)value;
9090

9191
/**
9292
* Creates and returns a new `FIRQuery` with the additional filter that documents must contain
@@ -100,7 +100,7 @@ NS_ASSUME_NONNULL_BEGIN
100100
* @return The created `FIRQuery`.
101101
*/
102102
// TODO(b/138855186): Expose to public once backend is ready.
103-
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path in:(id)value;
103+
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path in:(NSArray<id> *)value;
104104

105105
@end
106106

Firestore/Source/API/FIRQuery.mm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -546,21 +546,21 @@ - (Bound)boundFromFieldValues:(NSArray<id> *)fieldValues isBefore:(BOOL)isBefore
546546

547547
@implementation FIRQuery (Internal)
548548

549-
- (FIRQuery *)queryWhereField:(NSString *)field arrayContainsAny:(id)value {
549+
- (FIRQuery *)queryWhereField:(NSString *)field arrayContainsAny:(NSArray<id> *)value {
550550
return [self queryWithFilterOperator:Filter::Operator::ArrayContainsAny field:field value:value];
551551
}
552552

553-
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path arrayContainsAny:(id)value {
553+
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path arrayContainsAny:(NSArray<id> *)value {
554554
return [self queryWithFilterOperator:Filter::Operator::ArrayContainsAny
555555
path:path.internalValue
556556
value:value];
557557
}
558558

559-
- (FIRQuery *)queryWhereField:(NSString *)field in:(id)value {
559+
- (FIRQuery *)queryWhereField:(NSString *)field in:(NSArray<id> *)value {
560560
return [self queryWithFilterOperator:Filter::Operator::In field:field value:value];
561561
}
562562

563-
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path in:(id)value {
563+
- (FIRQuery *)queryWhereFieldPath:(FIRFieldPath *)path in:(NSArray<id> *)value {
564564
return [self queryWithFilterOperator:Filter::Operator::In path:path.internalValue value:value];
565565
}
566566

Firestore/core/src/firebase/firestore/api/query_core.mm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,10 @@ QuerySnapshot result(firestore_, query_, std::move(snapshot),
326326

327327
void Query::ValidateDisjunctiveFilterElements(
328328
const model::FieldValue& field_value, core::Filter::Operator op) const {
329-
if (field_value.type() != FieldValue::Type::Array ||
330-
field_value.array_value().size() == 0) {
329+
HARD_ASSERT(
330+
field_value.type() == FieldValue::Type::Array,
331+
"A FieldValue of Array type is required for disjunctive filters.");
332+
if (field_value.array_value().size() == 0) {
331333
ThrowInvalidArgument("Invalid Query. A non-empty array is required for '%s'"
332334
" filters.",
333335
Describe(op));

0 commit comments

Comments
 (0)