Skip to content

Commit 680503d

Browse files
cherylEnkiduwu-hui
andauthored
Add documentation for ppl (#15401)
Co-authored-by: wu-hui <[email protected]>
1 parent b1c17f7 commit 680503d

25 files changed

+963
-627
lines changed

Firestore/Swift/Source/ExpressionImplementation.swift

Lines changed: 270 additions & 165 deletions
Large diffs are not rendered by default.

Firestore/Swift/Source/Helper/PipelineHelper.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ enum Helper {
4747
result.append(Constant(key))
4848
result.append(sendableToExpr(value))
4949
}
50-
return FunctionExpression("map", result)
50+
return FunctionExpression(functionName: "map", args: result)
5151
}
5252

5353
static func array(_ elements: [Sendable?]) -> FunctionExpression {
5454
let transformedElements = elements.map { element in
5555
sendableToExpr(element)
5656
}
57-
return FunctionExpression("array", transformedElements)
57+
return FunctionExpression(functionName: "array", args: transformedElements)
5858
}
5959

6060
// This function is used to convert Swift type into Objective-C type.
File renamed without changes.

Firestore/Swift/Source/SwiftAPI/Firestore+Pipeline.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,43 @@
2222
import Foundation
2323

2424
@objc public extension Firestore {
25+
/// Creates a new `PipelineSource` to build and execute a data pipeline.
26+
///
27+
/// A pipeline is composed of a sequence of stages. Each stage processes the
28+
/// output from the previous one, and the final stage's output is the result of the
29+
/// pipeline's execution.
30+
///
31+
/// Example usage:
32+
/// ```swift
33+
/// let pipeline = firestore.pipeline()
34+
/// .collection("books")
35+
/// .where(Field("rating").isGreaterThan(4.5))
36+
/// .sort(Field("rating").descending())
37+
/// .limit(2)
38+
/// ```
39+
///
40+
/// Note on Execution: The stages are conceptual. The Firestore backend may
41+
/// optimize execution (e.g., reordering or merging stages) as long as the
42+
/// final result remains the same.
43+
///
44+
/// Important Limitations:
45+
/// - Pipelines operate on a request/response basis only.
46+
/// - They do not utilize or update the local SDK cache.
47+
/// - They do not support realtime snapshot listeners.
48+
///
49+
/// - Returns: A `PipelineSource` to begin defining the pipeline's stages.
2550
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
2651
@nonobjc func pipeline() -> PipelineSource {
2752
return PipelineSource(db: self) { stages, db in
2853
Pipeline(stages: stages, db: db)
2954
}
3055
}
3156

57+
/// Creates a `RealtimePipelineSource` for building and executing a realtime pipeline.
58+
///
59+
/// This is an internal method and should not be used directly.
60+
///
61+
/// - Returns: A `RealtimePipelineSource` for building a realtime pipeline.
3262
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
3363
@nonobjc internal func realtimePipeline() -> RealtimePipelineSource {
3464
return RealtimePipelineSource(db: self) { stages, db in

Firestore/Swift/Source/SwiftAPI/Pipeline/Aggregates/AggregateFunction.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,23 @@ extension AggregateFunction {
1818
}
1919
}
2020

21+
/// Represents an aggregate function in a pipeline.
22+
///
23+
/// An `AggregateFunction` is a function that computes a single value from a set of input values.
24+
///
25+
/// `AggregateFunction`s are typically used in the `aggregate` stage of a pipeline.
2126
public class AggregateFunction: AggregateBridgeWrapper, @unchecked Sendable {
2227
let bridge: AggregateFunctionBridge
2328

2429
let functionName: String
2530
let args: [Expression]
2631

27-
public init(_ functionName: String, _ args: [Expression]) {
32+
/// Creates a new `AggregateFunction`.
33+
///
34+
/// - Parameters:
35+
/// - functionName: The name of the aggregate function.
36+
/// - args: The arguments to the aggregate function.
37+
public init(functionName: String, args: [Expression]) {
2838
self.functionName = functionName
2939
self.args = args
3040
bridge = AggregateFunctionBridge(
@@ -34,6 +44,10 @@ public class AggregateFunction: AggregateBridgeWrapper, @unchecked Sendable {
3444
)
3545
}
3646

47+
/// Creates an `AliasedAggregate` from this aggregate function.
48+
///
49+
/// - Parameter name: The alias for the aggregate function.
50+
/// - Returns: An `AliasedAggregate` with the given alias.
3751
public func `as`(_ name: String) -> AliasedAggregate {
3852
return AliasedAggregate(aggregate: self, alias: name)
3953
}

Firestore/Swift/Source/SwiftAPI/Pipeline/Aggregates/AliasedAggregate.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
/// An `AggregateFunction` that has been given an alias.
1516
public struct AliasedAggregate {
16-
public let aggregate: AggregateFunction
17-
public let alias: String
17+
let aggregate: AggregateFunction
18+
19+
let alias: String
1820
}

Firestore/Swift/Source/SwiftAPI/Pipeline/Aggregates/CountAll.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@
3838
public class CountAll: AggregateFunction, @unchecked Sendable {
3939
/// Initializes a new `CountAll` aggregation.
4040
public init() {
41-
super.init("count", [])
41+
super.init(functionName: "count", args: [])
4242
}
4343
}

Firestore/Swift/Source/SwiftAPI/Pipeline/DistanceMeasure.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import Foundation
2222

23+
/// Represents the distance measure to be used in a vector similarity search.
2324
public struct DistanceMeasure: Sendable, Equatable, Hashable {
2425
let kind: Kind
2526

@@ -29,10 +30,13 @@ public struct DistanceMeasure: Sendable, Equatable, Hashable {
2930
case dotProduct = "dot_product"
3031
}
3132

33+
/// The Euclidean distance measure.
3234
public static let euclidean: DistanceMeasure = .init(kind: .euclidean)
3335

36+
/// The Cosine distance measure.
3437
public static let cosine: DistanceMeasure = .init(kind: .cosine)
3538

39+
/// The Dot Product distance measure.
3640
public static let dotProduct: DistanceMeasure = .init(kind: .dotProduct)
3741

3842
init(kind: Kind) {

Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/AliasedExpression.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
/// An `Expression` that has been given an alias.
1516
public struct AliasedExpression: Selectable, SelectableWrapper, Sendable {
1617
let alias: String
1718

0 commit comments

Comments
 (0)