Skip to content

Commit 33bc889

Browse files
cherylEnkiduwu-huincooke3
authored
Pipeline tests part 3 (#15005)
Co-authored-by: wu-hui <[email protected]> Co-authored-by: Nick Cooke <[email protected]>
1 parent c3cc79a commit 33bc889

File tree

15 files changed

+1870
-172
lines changed

15 files changed

+1870
-172
lines changed

Firestore/Source/API/FIRPipelineBridge.mm

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@
7373
using firebase::firestore::api::Union;
7474
using firebase::firestore::api::Unnest;
7575
using firebase::firestore::api::Where;
76+
using firebase::firestore::model::DeepClone;
7677
using firebase::firestore::model::FieldPath;
78+
using firebase::firestore::nanopb::MakeSharedMessage;
7779
using firebase::firestore::nanopb::SharedMessage;
7880
using firebase::firestore::util::ComparisonResult;
7981
using firebase::firestore::util::MakeCallback;
@@ -94,13 +96,24 @@ @implementation FIRExprBridge
9496
@end
9597

9698
@implementation FIRFieldBridge {
99+
FIRFieldPath *field_path;
97100
std::shared_ptr<Field> field;
98101
}
99102

100-
- (id)init:(NSString *)name {
103+
- (id)initWithName:(NSString *)name {
101104
self = [super init];
102105
if (self) {
103-
field = std::make_shared<Field>(MakeString(name));
106+
field_path = [FIRFieldPath pathWithDotSeparatedString:name];
107+
field = std::make_shared<Field>([field_path internalValue].CanonicalString());
108+
}
109+
return self;
110+
}
111+
112+
- (id)initWithPath:(FIRFieldPath *)path {
113+
self = [super init];
114+
if (self) {
115+
field_path = path;
116+
field = std::make_shared<Field>([field_path internalValue].CanonicalString());
104117
}
105118
return self;
106119
}
@@ -109,6 +122,10 @@ - (id)init:(NSString *)name {
109122
return field;
110123
}
111124

125+
- (NSString *)field_name {
126+
return MakeNSString([field_path internalValue].CanonicalString());
127+
}
128+
112129
@end
113130

114131
@implementation FIRConstantBridge {
@@ -560,7 +577,7 @@ @implementation FIRFindNearestStageBridge {
560577
FIRVectorValue *_vectorValue;
561578
NSString *_distanceMeasure;
562579
NSNumber *_limit;
563-
NSString *_Nullable _distanceField;
580+
FIRExprBridge *_Nullable _distanceField;
564581
Boolean isUserDataRead;
565582
std::shared_ptr<FindNearestStage> cpp_find_nearest;
566583
}
@@ -569,7 +586,7 @@ - (id)initWithField:(FIRFieldBridge *)field
569586
vectorValue:(FIRVectorValue *)vectorValue
570587
distanceMeasure:(NSString *)distanceMeasure
571588
limit:(NSNumber *_Nullable)limit
572-
distanceField:(NSString *_Nullable)distanceField {
589+
distanceField:(FIRExprBridge *_Nullable)distanceField {
573590
self = [super init];
574591
if (self) {
575592
_field = field;
@@ -584,21 +601,16 @@ - (id)initWithField:(FIRFieldBridge *)field
584601

585602
- (std::shared_ptr<api::Stage>)cppStageWithReader:(FSTUserDataReader *)reader {
586603
if (!isUserDataRead) {
587-
std::unordered_map<std::string,
588-
nanopb::SharedMessage<firebase::firestore::google_firestore_v1_Value>>
589-
optional_value;
604+
std::unordered_map<std::string, firebase::firestore::google_firestore_v1_Value> optional_value;
590605
if (_limit) {
591-
optional_value.emplace(
592-
std::make_pair(std::string("limit"),
593-
nanopb::SharedMessage<firebase::firestore::google_firestore_v1_Value>(
594-
[reader parsedQueryValue:_limit])));
606+
optional_value.emplace(std::make_pair(
607+
std::string("limit"), *DeepClone(*[reader parsedQueryValue:_limit]).release()));
595608
}
596609

597610
if (_distanceField) {
611+
std::shared_ptr<Expr> cpp_distance_field = [_distanceField cppExprWithReader:reader];
598612
optional_value.emplace(
599-
std::make_pair(std::string("distance_field"),
600-
nanopb::SharedMessage<firebase::firestore::google_firestore_v1_Value>(
601-
[reader parsedQueryValue:_distanceField])));
613+
std::make_pair(std::string("distance_field"), cpp_distance_field->to_proto()));
602614
}
603615

604616
FindNearestStage::DistanceMeasure::Measure measure_enum;

Firestore/Source/Public/FirebaseFirestore/FIRPipelineBridge.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
@class FIRTimestamp;
2424
@class FIRVectorValue;
2525
@class FIRPipelineBridge;
26+
@class FIRFieldPath;
2627

2728
NS_ASSUME_NONNULL_BEGIN
2829

@@ -34,7 +35,9 @@ NS_SWIFT_NAME(ExprBridge)
3435
NS_SWIFT_SENDABLE
3536
NS_SWIFT_NAME(FieldBridge)
3637
@interface FIRFieldBridge : FIRExprBridge
37-
- (id)init:(NSString *)name;
38+
- (id)initWithName:(NSString *)name;
39+
- (id)initWithPath:(FIRFieldPath *)path;
40+
- (NSString *)field_name;
3841
@end
3942

4043
NS_SWIFT_SENDABLE
@@ -160,7 +163,7 @@ NS_SWIFT_NAME(FindNearestStageBridge)
160163
vectorValue:(FIRVectorValue *)vectorValue
161164
distanceMeasure:(NSString *)distanceMeasure
162165
limit:(NSNumber *_Nullable)limit
163-
distanceField:(NSString *_Nullable)distanceField;
166+
distanceField:(FIRExprBridge *_Nullable)distanceField;
164167
@end
165168

166169
NS_SWIFT_SENDABLE

Firestore/Swift/Source/ExprImpl.swift

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@ public extension Expr {
2525

2626
// MARK: Arithmetic Operators
2727

28-
func add(_ second: Expr, _ others: Expr...) -> FunctionExpr {
29-
return FunctionExpr("add", [self, second] + others)
28+
func add(_ value: Expr) -> FunctionExpr {
29+
return FunctionExpr("add", [self, value])
3030
}
3131

32-
func add(_ second: Sendable, _ others: Sendable...) -> FunctionExpr {
33-
let exprs = [self] + [Helper.sendableToExpr(second)] + others
34-
.map { Helper.sendableToExpr($0) }
35-
return FunctionExpr("add", exprs)
32+
func add(_ value: Sendable) -> FunctionExpr {
33+
return FunctionExpr("add", [self, Helper.sendableToExpr(value)])
3634
}
3735

3836
func subtract(_ other: Expr) -> FunctionExpr {
@@ -43,14 +41,12 @@ public extension Expr {
4341
return FunctionExpr("subtract", [self, Helper.sendableToExpr(other)])
4442
}
4543

46-
func multiply(_ second: Expr, _ others: Expr...) -> FunctionExpr {
47-
return FunctionExpr("multiply", [self, second] + others)
44+
func multiply(_ value: Expr) -> FunctionExpr {
45+
return FunctionExpr("multiply", [self, value])
4846
}
4947

50-
func multiply(_ second: Sendable, _ others: Sendable...) -> FunctionExpr {
51-
let exprs = [self] + [Helper.sendableToExpr(second)] + others
52-
.map { Helper.sendableToExpr($0) }
53-
return FunctionExpr("multiply", exprs)
48+
func multiply(_ value: Sendable) -> FunctionExpr {
49+
return FunctionExpr("multiply", [self, Helper.sendableToExpr(value)])
5450
}
5551

5652
func divide(_ other: Expr) -> FunctionExpr {
@@ -89,34 +85,32 @@ public extension Expr {
8985
return BooleanExpr("array_contains", [self, Helper.sendableToExpr(element)])
9086
}
9187

92-
func arrayContainsAll(_ values: Expr...) -> BooleanExpr {
93-
return BooleanExpr("array_contains_all", [self] + values)
88+
func arrayContainsAll(_ values: [Expr]) -> BooleanExpr {
89+
return BooleanExpr("array_contains_all", [self, Helper.array(values)])
9490
}
9591

96-
func arrayContainsAll(_ values: Sendable...) -> BooleanExpr {
97-
let exprValues = values.map { Helper.sendableToExpr($0) }
98-
return BooleanExpr("array_contains_all", [self] + exprValues)
92+
func arrayContainsAll(_ values: [Sendable]) -> BooleanExpr {
93+
return BooleanExpr("array_contains_all", [self, Helper.array(values)])
9994
}
10095

101-
func arrayContainsAny(_ values: Expr...) -> BooleanExpr {
102-
return BooleanExpr("array_contains_any", [self] + values)
96+
func arrayContainsAny(_ values: [Expr]) -> BooleanExpr {
97+
return BooleanExpr("array_contains_any", [self, Helper.array(values)])
10398
}
10499

105-
func arrayContainsAny(_ values: Sendable...) -> BooleanExpr {
106-
let exprValues = values.map { Helper.sendableToExpr($0) }
107-
return BooleanExpr("array_contains_any", [self] + exprValues)
100+
func arrayContainsAny(_ values: [Sendable]) -> BooleanExpr {
101+
return BooleanExpr("array_contains_any", [self, Helper.array(values)])
108102
}
109103

110104
func arrayLength() -> FunctionExpr {
111105
return FunctionExpr("array_length", [self])
112106
}
113107

114-
func arrayOffset(_ offset: Int) -> FunctionExpr {
115-
return FunctionExpr("array_offset", [self, Helper.sendableToExpr(offset)])
108+
func arrayGet(_ offset: Int) -> FunctionExpr {
109+
return FunctionExpr("array_get", [self, Helper.sendableToExpr(offset)])
116110
}
117111

118-
func arrayOffset(_ offsetExpr: Expr) -> FunctionExpr {
119-
return FunctionExpr("array_offset", [self, offsetExpr])
112+
func arrayGet(_ offsetExpr: Expr) -> FunctionExpr {
113+
return FunctionExpr("array_get", [self, offsetExpr])
120114
}
121115

122116
func gt(_ other: Expr) -> BooleanExpr {
@@ -172,31 +166,28 @@ public extension Expr {
172166
return BooleanExpr("eq", [self, exprOther])
173167
}
174168

175-
func neq(_ others: Expr...) -> BooleanExpr {
176-
return BooleanExpr("neq", [self] + others)
169+
func neq(_ other: Expr) -> BooleanExpr {
170+
return BooleanExpr("neq", [self, other])
177171
}
178172

179-
func neq(_ others: Sendable...) -> BooleanExpr {
180-
let exprOthers = others.map { Helper.sendableToExpr($0) }
181-
return BooleanExpr("neq", [self] + exprOthers)
173+
func neq(_ other: Sendable) -> BooleanExpr {
174+
return BooleanExpr("neq", [self, Helper.sendableToExpr(other)])
182175
}
183176

184-
func eqAny(_ others: Expr...) -> BooleanExpr {
185-
return BooleanExpr("eq_any", [self] + others)
177+
func eqAny(_ others: [Expr]) -> BooleanExpr {
178+
return BooleanExpr("eq_any", [self, Helper.array(others)])
186179
}
187180

188-
func eqAny(_ others: Sendable...) -> BooleanExpr {
189-
let exprOthers = others.map { Helper.sendableToExpr($0) }
190-
return BooleanExpr("eq_any", [self] + exprOthers)
181+
func eqAny(_ others: [Sendable]) -> BooleanExpr {
182+
return BooleanExpr("eq_any", [self, Helper.array(others)])
191183
}
192184

193-
func notEqAny(_ others: Expr...) -> BooleanExpr {
194-
return BooleanExpr("not_eq_any", [self] + others)
185+
func notEqAny(_ others: [Expr]) -> BooleanExpr {
186+
return BooleanExpr("not_eq_any", [self, Helper.array(others)])
195187
}
196188

197-
func notEqAny(_ others: Sendable...) -> BooleanExpr {
198-
let exprOthers = others.map { Helper.sendableToExpr($0) }
199-
return BooleanExpr("not_eq_any", [self] + exprOthers)
189+
func notEqAny(_ others: [Sendable]) -> BooleanExpr {
190+
return BooleanExpr("not_eq_any", [self, Helper.array(others)])
200191
}
201192

202193
// MARK: Checks
@@ -237,12 +228,12 @@ public extension Expr {
237228
return FunctionExpr("char_length", [self])
238229
}
239230

240-
func like(_ pattern: String) -> FunctionExpr {
241-
return FunctionExpr("like", [self, Helper.sendableToExpr(pattern)])
231+
func like(_ pattern: String) -> BooleanExpr {
232+
return BooleanExpr("like", [self, Helper.sendableToExpr(pattern)])
242233
}
243234

244-
func like(_ pattern: Expr) -> FunctionExpr {
245-
return FunctionExpr("like", [self, pattern])
235+
func like(_ pattern: Expr) -> BooleanExpr {
236+
return BooleanExpr("like", [self, pattern])
246237
}
247238

248239
func regexContains(_ pattern: String) -> BooleanExpr {
@@ -414,13 +405,13 @@ public extension Expr {
414405
}
415406

416407
func logicalMinimum(_ second: Expr, _ others: Expr...) -> FunctionExpr {
417-
return FunctionExpr("logical_min", [self, second] + others)
408+
return FunctionExpr("logical_minimum", [self, second] + others)
418409
}
419410

420411
func logicalMinimum(_ second: Sendable, _ others: Sendable...) -> FunctionExpr {
421412
let exprs = [self] + [Helper.sendableToExpr(second)] + others
422413
.map { Helper.sendableToExpr($0) }
423-
return FunctionExpr("logical_min", exprs)
414+
return FunctionExpr("logical_minimum", exprs)
424415
}
425416

426417
// MARK: Vector Operations

Firestore/Swift/Source/Helper/PipelineHelper.swift

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,24 @@ enum Helper {
1818
return Constant.nil
1919
}
2020

21-
if value is Expr {
22-
return value as! Expr
23-
} else if value is [String: Sendable?] {
24-
return map(value as! [String: Sendable?])
25-
} else if value is [Sendable?] {
26-
return array(value as! [Sendable?])
21+
if let exprValue = value as? Expr {
22+
return exprValue
23+
} else if let dictionaryValue = value as? [String: Sendable?] {
24+
return map(dictionaryValue)
25+
} else if let arrayValue = value as? [Sendable?] {
26+
return array(arrayValue)
27+
} else if let timeUnitValue = value as? TimeUnit {
28+
return Constant(timeUnitValue.rawValue)
2729
} else {
2830
return Constant(value)
2931
}
3032
}
3133

3234
static func selectablesToMap(selectables: [Selectable]) -> [String: Expr] {
3335
let exprMap = selectables.reduce(into: [String: Expr]()) { result, selectable in
34-
let value = selectable as! SelectableWrapper
36+
guard let value = selectable as? SelectableWrapper else {
37+
fatalError("Selectable class must conform to SelectableWrapper.")
38+
}
3539
result[value.alias] = value.expr
3640
}
3741
return exprMap
@@ -55,22 +59,18 @@ enum Helper {
5559

5660
// This function is used to convert Swift type into Objective-C type.
5761
static func sendableToAnyObjectForRawStage(_ value: Sendable?) -> AnyObject {
58-
guard let value = value else {
59-
return Constant.nil.bridge
60-
}
61-
62-
guard !(value is NSNull) else {
62+
guard let value = value, !(value is NSNull) else {
6363
return Constant.nil.bridge
6464
}
6565

66-
if value is Expr {
67-
return (value as! Expr).toBridge()
68-
} else if value is AggregateFunction {
69-
return (value as! AggregateFunction).toBridge()
70-
} else if value is [String: Sendable?] {
71-
let mappedValue: [String: Sendable?] = (value as! [String: Sendable?]).mapValues {
72-
if $0 is AggregateFunction {
73-
return ($0 as! AggregateFunction).toBridge()
66+
if let exprValue = value as? Expr {
67+
return exprValue.toBridge()
68+
} else if let aggregateFunctionValue = value as? AggregateFunction {
69+
return aggregateFunctionValue.toBridge()
70+
} else if let dictionaryValue = value as? [String: Sendable?] {
71+
let mappedValue: [String: Sendable] = dictionaryValue.mapValues {
72+
if let aggFunc = $0 as? AggregateFunction {
73+
return aggFunc.toBridge()
7474
}
7575
return sendableToExpr($0).toBridge()
7676
}
@@ -79,4 +79,14 @@ enum Helper {
7979
return Constant(value).bridge
8080
}
8181
}
82+
83+
static func convertObjCToSwift(_ objValue: Sendable) -> Sendable? {
84+
switch objValue {
85+
case is NSNull:
86+
return nil
87+
88+
default:
89+
return objValue
90+
}
91+
}
8292
}

0 commit comments

Comments
 (0)