Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
bd0ce8f
create main branch of ppl
cherylEnkidu Feb 27, 2025
84691ab
Add stage API
cherylEnkidu Feb 27, 2025
8519a5e
Add stage API
cherylEnkidu Mar 3, 2025
454893b
Add stage API
cherylEnkidu Mar 7, 2025
ed1a19b
API changes
cherylEnkidu Mar 12, 2025
819853c
Add cpp stages and expressions
wu-hui Mar 11, 2025
1be141b
Add more APIs
cherylEnkidu Mar 18, 2025
8fd5f8a
add Field
cherylEnkidu Mar 18, 2025
039b919
merge in main branch
cherylEnkidu Mar 19, 2025
5127bd0
Add UserDataReader support for constant and expr in pipelines
wu-hui Mar 17, 2025
14d2e5c
Add bridge
cherylEnkidu Mar 20, 2025
9895936
merge in push-pqrpmwtupmwv
cherylEnkidu Mar 20, 2025
5d701f8
Add UserDataReader support for constant and expr in pipelines
wu-hui Mar 17, 2025
b2af1c6
solve merge conflicts
cherylEnkidu Mar 20, 2025
cec7f6b
Fix merge conflicts
cherylEnkidu Mar 20, 2025
30b9251
solve conflicts
cherylEnkidu Mar 20, 2025
1ad093a
format and fix conflicts
cherylEnkidu Mar 20, 2025
b59a4fd
Remove placeholder for the test case
cherylEnkidu Mar 21, 2025
7d73155
Support tests
cherylEnkidu Mar 25, 2025
828bb12
Fix bug in decoding
cherylEnkidu Mar 27, 2025
d1d0aa4
Add some convert functions
cherylEnkidu Apr 1, 2025
113da45
add tests
cherylEnkidu Apr 2, 2025
39803e5
replace Any with sendable
cherylEnkidu Apr 2, 2025
6c78523
Update PipelineResult
cherylEnkidu Apr 3, 2025
9598764
add expression and stages
cherylEnkidu Apr 14, 2025
5a7f61f
merge changes
cherylEnkidu Apr 17, 2025
a5f558f
add tests
cherylEnkidu Apr 17, 2025
be5b0b2
change implementation details
cherylEnkidu Apr 24, 2025
e699c17
Add get for ppl result
cherylEnkidu Apr 24, 2025
daf1b68
revert test settings
cherylEnkidu Apr 24, 2025
5b2bd88
Change cmake version
cherylEnkidu Apr 25, 2025
04a16e2
merge in cmake settings
cherylEnkidu Apr 25, 2025
d324c5d
Merge branch 'cheryllin/ppl' into cheryllin/pplapi
cherylEnkidu Apr 26, 2025
23305c0
remove unused variable
cherylEnkidu Apr 28, 2025
6dd3515
revert settinggs
cherylEnkidu Apr 28, 2025
8ff71c2
add expressions
cherylEnkidu May 6, 2025
2372405
Add documentation to Pipeline.swift
cherylEnkidu May 6, 2025
c7ff4b7
merge in main
cherylEnkidu May 6, 2025
d5be6a0
Merge branch 'cheryllin/ppl' into cheryllin/pplapi
cherylEnkidu May 6, 2025
591816b
Fix replace with
cherylEnkidu May 7, 2025
0098829
change tests
cherylEnkidu May 8, 2025
4fb738d
Address feebacks 2
cherylEnkidu May 12, 2025
6ec8b6c
Address feedbacks 3
cherylEnkidu May 13, 2025
fd51b7b
change mutating fields
cherylEnkidu May 13, 2025
469b768
[Firestore] On SPM, import FirebaseFirestoreInternalWrapper (#14848)
ncooke3 May 13, 2025
ba94c32
add version restrictions
cherylEnkidu May 13, 2025
d1d1a89
Fix CI tests
cherylEnkidu May 15, 2025
65475b6
enable nightly build
cherylEnkidu May 15, 2025
f4b00ab
revert settings
cherylEnkidu May 15, 2025
f066ded
add tests and fix bugs
cherylEnkidu May 23, 2025
2437141
merge in base branch
cherylEnkidu May 23, 2025
71820c7
fix warning
cherylEnkidu May 23, 2025
8ce2a65
change addStage to rawStage
cherylEnkidu Jun 6, 2025
96c1710
fix build error
cherylEnkidu Jun 6, 2025
3e4d71a
remove local time
cherylEnkidu Jun 11, 2025
51086da
Add Constant tests
cherylEnkidu Jun 10, 2025
0f7d8ec
add more tests
cherylEnkidu Jun 11, 2025
38b89eb
add more tests
cherylEnkidu Jun 11, 2025
3a5ce84
More tests, some error is waiting for fix
cherylEnkidu Jun 11, 2025
69e9255
fix replacewith bug
cherylEnkidu Jun 11, 2025
5a2a98f
fix union stage
cherylEnkidu Jun 12, 2025
990c698
fix bugs in raw stage and unnest stage
cherylEnkidu Jun 16, 2025
aad77ae
Move test helper and fix raw stage test
cherylEnkidu Jun 17, 2025
be45ad4
add more tests
cherylEnkidu Jun 17, 2025
236b7b8
merge
cherylEnkidu Jun 18, 2025
5272a73
Fix memory error
cherylEnkidu Jun 18, 2025
2cb72fe
fix memory error in findnearst option
cherylEnkidu Jun 18, 2025
38deb73
replace varadic list with array and add tests
cherylEnkidu Jun 18, 2025
bb87efd
add tests
cherylEnkidu Jun 18, 2025
d6dfc51
add more tests
cherylEnkidu Jun 20, 2025
b4d5e8b
more tests
cherylEnkidu Jun 21, 2025
f1c025d
add test for timestamp
cherylEnkidu Jun 23, 2025
97599fd
add tests
cherylEnkidu Jun 24, 2025
b47a5cd
Fix bytes to data
cherylEnkidu Jun 24, 2025
09a0466
fix data type
cherylEnkidu Jun 24, 2025
a367798
fix add/multiply
cherylEnkidu Jun 26, 2025
fdf69ee
add more tests part 1
cherylEnkidu Jun 26, 2025
e063c84
add page test
cherylEnkidu Jun 30, 2025
78180b7
merge in base
cherylEnkidu Jun 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions Firestore/Source/API/FIRPipelineBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@
using firebase::firestore::api::Union;
using firebase::firestore::api::Unnest;
using firebase::firestore::api::Where;
using firebase::firestore::model::DeepClone;
using firebase::firestore::model::FieldPath;
using firebase::firestore::nanopb::MakeSharedMessage;
using firebase::firestore::nanopb::SharedMessage;
using firebase::firestore::util::ComparisonResult;
using firebase::firestore::util::MakeCallback;
Expand All @@ -94,13 +96,24 @@ @implementation FIRExprBridge
@end

@implementation FIRFieldBridge {
FIRFieldPath *field_path;
std::shared_ptr<Field> field;
}

- (id)init:(NSString *)name {
- (id)initWithName:(NSString *)name {
self = [super init];
if (self) {
field = std::make_shared<Field>(MakeString(name));
field_path = [FIRFieldPath pathWithDotSeparatedString:name];
field = std::make_shared<Field>([field_path internalValue].CanonicalString());
}
return self;
}

- (id)initWithPath:(FIRFieldPath *)path {
self = [super init];
if (self) {
field_path = path;
field = std::make_shared<Field>([field_path internalValue].CanonicalString());
}
return self;
}
Expand All @@ -109,6 +122,10 @@ - (id)init:(NSString *)name {
return field;
}

- (NSString *)field_name {
return MakeNSString([field_path internalValue].CanonicalString());
}

@end

@implementation FIRConstantBridge {
Expand Down Expand Up @@ -560,7 +577,7 @@ @implementation FIRFindNearestStageBridge {
FIRVectorValue *_vectorValue;
NSString *_distanceMeasure;
NSNumber *_limit;
NSString *_Nullable _distanceField;
FIRExprBridge *_Nullable _distanceField;
Boolean isUserDataRead;
std::shared_ptr<FindNearestStage> cpp_find_nearest;
}
Expand All @@ -569,7 +586,7 @@ - (id)initWithField:(FIRFieldBridge *)field
vectorValue:(FIRVectorValue *)vectorValue
distanceMeasure:(NSString *)distanceMeasure
limit:(NSNumber *_Nullable)limit
distanceField:(NSString *_Nullable)distanceField {
distanceField:(FIRExprBridge *_Nullable)distanceField {
self = [super init];
if (self) {
_field = field;
Expand All @@ -584,21 +601,16 @@ - (id)initWithField:(FIRFieldBridge *)field

- (std::shared_ptr<api::Stage>)cppStageWithReader:(FSTUserDataReader *)reader {
if (!isUserDataRead) {
std::unordered_map<std::string,
nanopb::SharedMessage<firebase::firestore::google_firestore_v1_Value>>
optional_value;
std::unordered_map<std::string, firebase::firestore::google_firestore_v1_Value> optional_value;
if (_limit) {
optional_value.emplace(
std::make_pair(std::string("limit"),
nanopb::SharedMessage<firebase::firestore::google_firestore_v1_Value>(
[reader parsedQueryValue:_limit])));
optional_value.emplace(std::make_pair(
std::string("limit"), *DeepClone(*[reader parsedQueryValue:_limit]).release()));
}

if (_distanceField) {
std::shared_ptr<Expr> cpp_distance_field = [_distanceField cppExprWithReader:reader];
optional_value.emplace(
std::make_pair(std::string("distance_field"),
nanopb::SharedMessage<firebase::firestore::google_firestore_v1_Value>(
[reader parsedQueryValue:_distanceField])));
std::make_pair(std::string("distance_field"), cpp_distance_field->to_proto()));
}

FindNearestStage::DistanceMeasure::Measure measure_enum;
Expand Down
7 changes: 5 additions & 2 deletions Firestore/Source/Public/FirebaseFirestore/FIRPipelineBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
@class FIRTimestamp;
@class FIRVectorValue;
@class FIRPipelineBridge;
@class FIRFieldPath;

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -34,7 +35,9 @@ NS_SWIFT_NAME(ExprBridge)
NS_SWIFT_SENDABLE
NS_SWIFT_NAME(FieldBridge)
@interface FIRFieldBridge : FIRExprBridge
- (id)init:(NSString *)name;
- (id)initWithName:(NSString *)name;
- (id)initWithPath:(FIRFieldPath *)path;
- (NSString *)field_name;
@end

NS_SWIFT_SENDABLE
Expand Down Expand Up @@ -160,7 +163,7 @@ NS_SWIFT_NAME(FindNearestStageBridge)
vectorValue:(FIRVectorValue *)vectorValue
distanceMeasure:(NSString *)distanceMeasure
limit:(NSNumber *_Nullable)limit
distanceField:(NSString *_Nullable)distanceField;
distanceField:(FIRExprBridge *_Nullable)distanceField;
@end

NS_SWIFT_SENDABLE
Expand Down
85 changes: 38 additions & 47 deletions Firestore/Swift/Source/ExprImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

extension Expr {
func toBridge() -> ExprBridge {

Check failure on line 16 in Firestore/Swift/Source/ExprImpl.swift

View workflow job for this annotation

GitHub Actions / spm-binary / spm (macos-14, Xcode_16.2, iOS)

cannot find type 'ExprBridge' in scope

Check failure on line 16 in Firestore/Swift/Source/ExprImpl.swift

View workflow job for this annotation

GitHub Actions / spm-binary / spm (macos-15, Xcode_16.4, iOS)

cannot find type 'ExprBridge' in scope
return (self as! BridgeWrapper).bridge
}
}
Expand All @@ -25,14 +25,12 @@

// MARK: Arithmetic Operators

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

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

func subtract(_ other: Expr) -> FunctionExpr {
Expand All @@ -43,14 +41,12 @@
return FunctionExpr("subtract", [self, Helper.sendableToExpr(other)])
}

func multiply(_ second: Expr, _ others: Expr...) -> FunctionExpr {
return FunctionExpr("multiply", [self, second] + others)
func multiply(_ value: Expr) -> FunctionExpr {
return FunctionExpr("multiply", [self, value])
}

func multiply(_ second: Sendable, _ others: Sendable...) -> FunctionExpr {
let exprs = [self] + [Helper.sendableToExpr(second)] + others
.map { Helper.sendableToExpr($0) }
return FunctionExpr("multiply", exprs)
func multiply(_ value: Sendable) -> FunctionExpr {
return FunctionExpr("multiply", [self, Helper.sendableToExpr(value)])
}

func divide(_ other: Expr) -> FunctionExpr {
Expand Down Expand Up @@ -89,34 +85,32 @@
return BooleanExpr("array_contains", [self, Helper.sendableToExpr(element)])
}

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

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

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

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

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

func arrayOffset(_ offset: Int) -> FunctionExpr {
return FunctionExpr("array_offset", [self, Helper.sendableToExpr(offset)])
func arrayGet(_ offset: Int) -> FunctionExpr {
return FunctionExpr("array_get", [self, Helper.sendableToExpr(offset)])
}

func arrayOffset(_ offsetExpr: Expr) -> FunctionExpr {
return FunctionExpr("array_offset", [self, offsetExpr])
func arrayGet(_ offsetExpr: Expr) -> FunctionExpr {
return FunctionExpr("array_get", [self, offsetExpr])
}

func gt(_ other: Expr) -> BooleanExpr {
Expand Down Expand Up @@ -172,31 +166,28 @@
return BooleanExpr("eq", [self, exprOther])
}

func neq(_ others: Expr...) -> BooleanExpr {
return BooleanExpr("neq", [self] + others)
func neq(_ other: Expr) -> BooleanExpr {
return BooleanExpr("neq", [self, other])
}

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

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

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

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

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

// MARK: Checks
Expand Down Expand Up @@ -237,12 +228,12 @@
return FunctionExpr("char_length", [self])
}

func like(_ pattern: String) -> FunctionExpr {
return FunctionExpr("like", [self, Helper.sendableToExpr(pattern)])
func like(_ pattern: String) -> BooleanExpr {
return BooleanExpr("like", [self, Helper.sendableToExpr(pattern)])
}

func like(_ pattern: Expr) -> FunctionExpr {
return FunctionExpr("like", [self, pattern])
func like(_ pattern: Expr) -> BooleanExpr {
return BooleanExpr("like", [self, pattern])
}

func regexContains(_ pattern: String) -> BooleanExpr {
Expand Down Expand Up @@ -414,13 +405,13 @@
}

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

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

// MARK: Vector Operations
Expand Down
50 changes: 30 additions & 20 deletions Firestore/Swift/Source/Helper/PipelineHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,24 @@ enum Helper {
return Constant.nil
}

if value is Expr {
return value as! Expr
} else if value is [String: Sendable?] {
return map(value as! [String: Sendable?])
} else if value is [Sendable?] {
return array(value as! [Sendable?])
if let exprValue = value as? Expr {
return exprValue
} else if let dictionaryValue = value as? [String: Sendable?] {
return map(dictionaryValue)
} else if let arrayValue = value as? [Sendable?] {
return array(arrayValue)
} else if let timeUnitValue = value as? TimeUnit {
return Constant(timeUnitValue.rawValue)
} else {
return Constant(value)
}
}

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

// This function is used to convert Swift type into Objective-C type.
static func sendableToAnyObjectForRawStage(_ value: Sendable?) -> AnyObject {
guard let value = value else {
return Constant.nil.bridge
}

guard !(value is NSNull) else {
guard let value = value, !(value is NSNull) else {
return Constant.nil.bridge
}

if value is Expr {
return (value as! Expr).toBridge()
} else if value is AggregateFunction {
return (value as! AggregateFunction).toBridge()
} else if value is [String: Sendable?] {
let mappedValue: [String: Sendable?] = (value as! [String: Sendable?]).mapValues {
if $0 is AggregateFunction {
return ($0 as! AggregateFunction).toBridge()
if let exprValue = value as? Expr {
return exprValue.toBridge()
} else if let aggregateFunctionValue = value as? AggregateFunction {
return aggregateFunctionValue.toBridge()
} else if let dictionaryValue = value as? [String: Sendable?] {
let mappedValue: [String: Sendable] = dictionaryValue.mapValues {
if let aggFunc = $0 as? AggregateFunction {
return aggFunc.toBridge()
}
return sendableToExpr($0).toBridge()
}
Expand All @@ -79,4 +79,14 @@ enum Helper {
return Constant(value).bridge
}
}

static func convertObjCToSwift(_ objValue: Sendable) -> Sendable? {
switch objValue {
case is NSNull:
return nil

default:
return objValue
}
}
}
Loading
Loading