Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
f1b5b5d
[realppl 3] Arithmetic and comparison expressions
wu-hui Apr 14, 2025
6294868
[realppl 4] Array, debug, field and logical expressions
wu-hui Apr 16, 2025
6c0a698
[realppl 5] map,string,timestamp and mirroring semantics
wu-hui Apr 17, 2025
8efed9e
[realppl 6] offline ppl evaluation and tests
wu-hui Apr 24, 2025
0a8821c
[realppl 7] realppl integration with remote/local and unit tests
wu-hui Apr 30, 2025
f79f655
Remove Fuzzer
wu-hui May 27, 2025
8b8d4a2
[realppl 8] realppl spec tests
wu-hui May 13, 2025
0d65b86
[realppl 9] realppl public api and integration tests
wu-hui Apr 30, 2025
a1ad8f9
[realppl 10] Add server timestamp support
wu-hui Jun 16, 2025
3a10495
[realppl 11] Add query to pipeline support
wu-hui Jul 9, 2025
5a50bd6
Hide realtime pipelines
wu-hui Sep 12, 2025
a54bd45
address API feedbacks
cherylEnkidu Sep 21, 2025
e76d2a2
add documentation
cherylEnkidu Sep 21, 2025
fac2f83
rename Firestore/Swift/Source/ExprImpl.swift
cherylEnkidu Sep 21, 2025
2951a6c
expand expr to expression
cherylEnkidu Sep 25, 2025
afa920e
move files
cherylEnkidu Sep 25, 2025
d77d6d5
move files
cherylEnkidu Sep 25, 2025
18fbbae
move file
cherylEnkidu Sep 25, 2025
7c7eb75
Separate PipelineSource and RealtimePipelineSource
cherylEnkidu Sep 25, 2025
caf8158
add abs()
cherylEnkidu Sep 25, 2025
fb482c7
add arrayReverse
cherylEnkidu Sep 25, 2025
62434c1
add ceil()
cherylEnkidu Sep 25, 2025
d5d5c9d
add collectionId()
cherylEnkidu Sep 26, 2025
11bf771
add countDistinct()
cherylEnkidu Sep 26, 2025
0e39951
[realppl 8] realppl spec tests
wu-hui May 13, 2025
016dac0
[realppl 9] realppl public api and integration tests
wu-hui Apr 30, 2025
00c6256
add exp()
cherylEnkidu Sep 29, 2025
854b6bb
[realppl 10] Add query to pipeline support
wu-hui Jul 9, 2025
814074f
make all bit operations internal
cherylEnkidu Sep 29, 2025
54461f1
add floor()
cherylEnkidu Sep 29, 2025
8e8557f
add length()
cherylEnkidu Sep 29, 2025
ead6684
hide manhattanDistance()
cherylEnkidu Sep 29, 2025
c720527
add ln()
cherylEnkidu Sep 30, 2025
b51b545
Hide realtime pipelines
wu-hui Sep 12, 2025
69ced35
add pow()
cherylEnkidu Sep 30, 2025
3d0a3d3
hide replace expression
cherylEnkidu Sep 30, 2025
617feb4
rename substring
cherylEnkidu Sep 30, 2025
5bc46e3
add more expressions
cherylEnkidu Sep 30, 2025
452875f
make internal impl of Order public
cherylEnkidu Sep 30, 2025
3a258b2
rename timestampSubtract
cherylEnkidu Sep 30, 2025
1c00eea
refactor snapshot
cherylEnkidu Sep 30, 2025
aaa7855
move file
cherylEnkidu Sep 30, 2025
d02c044
remove backpointer to parent
cherylEnkidu Sep 30, 2025
fd8ed65
equivalent()
cherylEnkidu Sep 30, 2025
418e3a6
merge in base branch
cherylEnkidu Sep 30, 2025
e42cce2
merge in base 2
cherylEnkidu Sep 30, 2025
2fb7a14
add concat()
cherylEnkidu Oct 1, 2025
8422b15
add currentTimestamp()
cherylEnkidu Oct 1, 2025
45797e1
hide equivalent
cherylEnkidu Oct 1, 2025
b377edb
add ifAbsent and error
cherylEnkidu Oct 1, 2025
903425b
add join()
cherylEnkidu Oct 1, 2025
50b673e
rename logical
cherylEnkidu Oct 1, 2025
41fcae2
add name tag for FunctionExpression
cherylEnkidu Oct 7, 2025
a4d33e4
add missing tags
cherylEnkidu Oct 9, 2025
91b0dec
add documentations
cherylEnkidu Oct 9, 2025
d8c5c81
add documentations 2
cherylEnkidu Oct 9, 2025
88586a1
rebase to feature branch
cherylEnkidu Oct 22, 2025
43fb9ef
fix rebase error 1
cherylEnkidu Oct 22, 2025
77e4556
resolve rebase error
cherylEnkidu Oct 22, 2025
dfce952
fix broken tests
cherylEnkidu Oct 23, 2025
8005a23
format code
cherylEnkidu Oct 23, 2025
7a357c2
add map_set
cherylEnkidu Oct 24, 2025
bc1a2b7
add equivalent
cherylEnkidu Oct 24, 2025
72b89fd
add TimestampTrunc
cherylEnkidu Oct 24, 2025
2e18c4a
Revert "add equivalent"
cherylEnkidu Oct 24, 2025
3475b66
solve rebase error
cherylEnkidu Oct 24, 2025
585c525
add trim()
cherylEnkidu Oct 27, 2025
b6ab3a0
remove Equivalent
cherylEnkidu Oct 27, 2025
688d164
add duplicate alias checking
cherylEnkidu Oct 28, 2025
62ea686
optimize aliasedAggregatesToMap
cherylEnkidu Oct 28, 2025
109a2f8
improve code
cherylEnkidu Oct 29, 2025
ef36ec2
make duplicate alias recoverable error
cherylEnkidu Nov 4, 2025
56b2378
add tests
cherylEnkidu Nov 4, 2025
3a9c32e
merge in base branch
cherylEnkidu Nov 4, 2025
9994cec
solve rebase error
cherylEnkidu Nov 4, 2025
650258b
improve readability
cherylEnkidu Nov 4, 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
44 changes: 38 additions & 6 deletions Firestore/Swift/Source/Helper/PipelineHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
// limitations under the License.

enum Helper {
enum HelperError: Error, LocalizedError {
case duplicateAlias(String)

public var errorDescription: String? {
switch self {
case let .duplicateAlias(message):
return message
}
}
}

static func sendableToExpr(_ value: Sendable?) -> Expression {
guard let value = value else {
return Constant.nil
Expand All @@ -31,14 +42,35 @@ enum Helper {
}
}

static func selectablesToMap(selectables: [Selectable]) -> [String: Expression] {
let exprMap = selectables.reduce(into: [String: Expression]()) { result, selectable in
static func selectablesToMap(selectables: [Selectable]) -> ([String: Expression], Error?) {
var exprMap = [String: Expression]()
for selectable in selectables {
guard let value = selectable as? SelectableWrapper else {
fatalError("Selectable class must conform to SelectableWrapper.")
}
result[value.alias] = value.expr
let alias = value.alias
if exprMap.keys.contains(alias) {
return ([:], HelperError.duplicateAlias("Duplicate alias '\(alias)' found in selectables."))
}
exprMap[alias] = value.expr
}
return (exprMap, nil)
}

static func aliasedAggregatesToMap(accumulators: [AliasedAggregate])
-> ([String: AggregateFunction], Error?) {
var accumulatorMap = [String: AggregateFunction]()
for aliasedAggregate in accumulators {
let alias = aliasedAggregate.alias
if accumulatorMap.keys.contains(alias) {
return (
[:],
HelperError.duplicateAlias("Duplicate alias '\(alias)' found in accumulators.")
)
}
accumulatorMap[alias] = aliasedAggregate.aggregate
}
return exprMap
return (accumulatorMap, nil)
}

static func map(_ elements: [String: Sendable?]) -> FunctionExpression {
Expand Down Expand Up @@ -66,11 +98,11 @@ enum Helper {
if let exprValue = value as? Expression {
return exprValue.toBridge()
} else if let aggregateFunctionValue = value as? AggregateFunction {
return aggregateFunctionValue.toBridge()
return aggregateFunctionValue.bridge
} else if let dictionaryValue = value as? [String: Sendable?] {
let mappedValue: [String: Sendable] = dictionaryValue.mapValues {
if let aggFunc = $0 as? AggregateFunction {
return aggFunc.toBridge()
return aggFunc.bridge
}
return sendableToExpr($0).toBridge()
}
Expand Down
77 changes: 57 additions & 20 deletions Firestore/Swift/Source/Stages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ import Foundation
protocol Stage {
var name: String { get }
var bridge: StageBridge { get }
var errorMessage: String? { get }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's document the purpose and the behavior of this field in detail, because this is fairly ununsual.

}

extension Stage {
var errorMessage: String? {
return nil
}
}

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
Expand Down Expand Up @@ -147,17 +154,19 @@ class AddFields: Stage {
let name: String = "add_fields"
let bridge: StageBridge
private var selectables: [Selectable]
let errorMessage: String?

init(selectables: [Selectable]) {
self.selectables = selectables
let objc_accumulators = selectables.reduce(into: [String: ExprBridge]()) {
result,
selectable
in
let selectableWrapper = selectable as! SelectableWrapper
result[selectableWrapper.alias] = selectableWrapper.expr.toBridge()
let (map, error) = Helper.selectablesToMap(selectables: selectables)
if let error = error {
errorMessage = error.localizedDescription
bridge = AddFieldsStageBridge(fields: [:])
} else {
errorMessage = nil
let objcAccumulators = map.mapValues { $0.toBridge() }
bridge = AddFieldsStageBridge(fields: objcAccumulators)
}
bridge = AddFieldsStageBridge(fields: objc_accumulators)
}
}

Expand All @@ -182,23 +191,37 @@ class RemoveFieldsStage: Stage {
class Select: Stage {
let name: String = "select"
let bridge: StageBridge
let errorMessage: String?

init(selections: [Selectable]) {
let map = Helper.selectablesToMap(selectables: selections)
bridge = SelectStageBridge(selections: map
.mapValues { Helper.sendableToExpr($0).toBridge() })
let (map, error) = Helper.selectablesToMap(selectables: selections)
if let error = error {
errorMessage = error.localizedDescription
bridge = SelectStageBridge(selections: [:])
} else {
errorMessage = nil
let objcSelections = map.mapValues { Helper.sendableToExpr($0).toBridge() }
bridge = SelectStageBridge(selections: objcSelections)
}
}
}

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
class Distinct: Stage {
let name: String = "distinct"
let bridge: StageBridge
let errorMessage: String?

init(groups: [Selectable]) {
let map = Helper.selectablesToMap(selectables: groups)
bridge = DistinctStageBridge(groups: map
.mapValues { Helper.sendableToExpr($0).toBridge() })
let (map, error) = Helper.selectablesToMap(selectables: groups)
if let error = error {
errorMessage = error.localizedDescription
bridge = DistinctStageBridge(groups: [:])
} else {
errorMessage = nil
let objcGroups = map.mapValues { Helper.sendableToExpr($0).toBridge() }
bridge = DistinctStageBridge(groups: objcGroups)
}
}
}

Expand All @@ -208,18 +231,32 @@ class Aggregate: Stage {
let bridge: StageBridge
private var accumulators: [AliasedAggregate]
private var groups: [String: Expression] = [:]
let errorMessage: String?

init(accumulators: [AliasedAggregate], groups: [Selectable]?) {
self.accumulators = accumulators
if groups != nil {
self.groups = Helper.selectablesToMap(selectables: groups!)
}
let accumulatorsMap = accumulators
.reduce(into: [String: AggregateFunctionBridge]()) { result, accumulator in
result[accumulator.alias] = accumulator.aggregate.bridge

if let groups = groups {
let (map, error) = Helper.selectablesToMap(selectables: groups)
if let error = error {
errorMessage = error.localizedDescription
bridge = AggregateStageBridge(accumulators: [:], groups: [:])
return
}
self.groups = map
}

let (accumulatorsMap, error) = Helper.aliasedAggregatesToMap(accumulators: accumulators)
if let error = error {
errorMessage = error.localizedDescription
bridge = AggregateStageBridge(accumulators: [:], groups: [:])
return
}

errorMessage = nil
let accumulatorBridgesMap = accumulatorsMap.mapValues { $0.bridge }
bridge = AggregateStageBridge(
accumulators: accumulatorsMap,
accumulators: accumulatorBridgesMap,
groups: self.groups.mapValues { Helper.sendableToExpr($0).toBridge() }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

extension AggregateFunction {
func toBridge() -> AggregateFunctionBridge {
return (self as AggregateBridgeWrapper).bridge
}
}

/// Represents an aggregate function in a pipeline.
///
/// An `AggregateFunction` is a function that computes a single value from a set of input values.
Expand Down
Loading
Loading