Skip to content

Ppl Options #14843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 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
fd8b97e
first draft
cherylEnkidu May 12, 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
Prev Previous commit
first draft
  • Loading branch information
cherylEnkidu committed May 12, 2025
commit fd8b97ef14562bab17001214d8747dd7532768f9
65 changes: 65 additions & 0 deletions Firestore/Swift/Source/SwiftAPI/Pipeline/Options.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
public protocol OptionProtocol: Sendable {}

public struct ExplainOptions: OptionProtocol {
public var mode: String = ""
public var outputFormat: String = ""
public var verbosity: String = ""
public var indexRecommendation: Bool = false
public var profiles: String = ""
public var redact: Bool = false

public init(mode: String = "",
outputFormat: String = "",
verbosity: String = "",
indexRecommendation: Bool = false,
profiles: String = "",
redact: Bool = false) {
self.mode = mode
self.outputFormat = outputFormat
self.verbosity = verbosity
self.indexRecommendation = indexRecommendation
self.profiles = profiles
self.redact = redact
}
}

public struct GenericOptions: OptionProtocol {
var values: [String: Sendable]
public init(_ values: [String: Sendable] = [:]) {
self.values = values
}
}

public struct IndexMode: OptionProtocol {
var values: String
public init(_ values: String) {
self.values = values
}
}

@resultBuilder
public struct OptionBuilder {
public static func buildBlock(_ components: [OptionProtocol]...) -> [OptionProtocol] {
components.flatMap { $0 }
}

public static func buildOptional(_ components: [OptionProtocol]?) -> [OptionProtocol] {
components ?? []
}

public static func buildExpression(_ components: OptionProtocol) -> [OptionProtocol] {
[components]
}

public static func buildExpression(_ components: [OptionProtocol]) -> [OptionProtocol] {
components
}

public static func buildEither(first components: [OptionProtocol]) -> [OptionProtocol] {
components
}

public static func buildEither(second components: [OptionProtocol]) -> [OptionProtocol] {
components
}
}
17 changes: 16 additions & 1 deletion Firestore/Swift/Source/SwiftAPI/Pipeline/Pipeline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,22 @@ public struct Pipeline: @unchecked Sendable {
///
/// - Throws: An error if the pipeline execution fails on the backend.
/// - Returns: A `PipelineSnapshot` containing the result of the pipeline execution.
public func execute() async throws -> PipelineSnapshot {
public func execute(@OptionBuilder options: () -> [OptionProtocol] = { [] }) async throws
-> PipelineSnapshot {
return try await withCheckedThrowingContinuation { continuation in
self.bridge.execute { result, error in
if let error {
continuation.resume(throwing: error)
} else {
continuation.resume(returning: PipelineSnapshot(result!, pipeline: self))
}
}
}
}

public func execute2(explainOptions: ExplainOptions? = nil,
indexMode: String? = nil,
genericOptions: GenericOptions? = nil) async throws -> PipelineSnapshot {
return try await withCheckedThrowingContinuation { continuation in
self.bridge.execute { result, error in
if let error {
Expand Down
51 changes: 51 additions & 0 deletions Firestore/Swift/Tests/Integration/PipelineApiTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,57 @@ final class PipelineTests: FSTIntegrationTestCase {
let _: PipelineSnapshot = try await pipeline.execute()
}

func testPipelineOptions() async throws {
let pipelineSource: PipelineSource = db.pipeline()

let pipeline: Pipeline = pipelineSource.documents(
[db.collection("foo").document("bar"), db.document("foo/baz")]
)

let developmentModeEnabled = true

let _: PipelineSnapshot = try await pipeline.execute {
// Use different options under different scenarios
if developmentModeEnabled {
ExplainOptions(
mode: "analyze",
outputFormat: "json",
verbosity: "execution_tree",
indexRecommendation: true,
profiles: "bytes_throughput",
redact: false
)
IndexMode("recommended")
} else {
GenericOptions(
["option_not_known_to_sdk": true]
)
}

// Default options
GenericOptions(
["option_not_known_to_sdk": true]
)
}

let _: PipelineSnapshot = try await pipeline.execute2(
// Use different options under different scenarios
explainOptions:
ExplainOptions(
mode: "analyze",
outputFormat: "json",
verbosity: "execution_tree",
indexRecommendation: true,
profiles: "bytes_throughput",
redact: false
),
indexMode: "recommended",
genericOptions: GenericOptions(
["option_not_known_to_sdk": true]
)
)
}

func testWhereStage() async throws {
_ = db.pipeline().collection("books")
.where(
Expand Down
Loading