Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
66 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
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
Next Next commit
add documentation
  • Loading branch information
cherylEnkidu committed Sep 21, 2025
commit e76d2a2bc6da164f4590b2213d60d32eb5331c53
60 changes: 50 additions & 10 deletions Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/Constant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@
@_exported import FirebaseFirestoreInternal
#endif // SWIFT_PACKAGE

///
/// A `Constant` is an `Expression` that represents a fixed, literal value within a Firestore pipeline.
///
/// `Constant`s are used to introduce literal values into a query, which can be useful for:
/// - Comparing a field to a specific value in a `where` clause.
/// - Adding new fields with fixed values using `addFields`.
/// - Providing literal arguments to functions like `sum` or `average`.
///
/// Example of using a `Constant` to add a new field:
/// ```swift
/// // Add a new field "source" with the value "manual" to each document
/// firestore.pipeline()
/// .collection("entries")
/// .addFields([
/// Constant("manual").as("source")
/// ])
/// ```
public struct Constant: Expression, BridgeWrapper, @unchecked Sendable {
let bridge: ExprBridge

Expand All @@ -33,55 +50,78 @@ public struct Constant: Expression, BridgeWrapper, @unchecked Sendable {
}
}

// Initializer for integer
/// Creates a new `Constant` expression from an integer literal.
///
/// - Parameter value: The integer value.
public init(_ value: Int) {
self.init(value as Any)
}

// Initializer for double
/// Creates a new `Constant` expression from a double-precision floating-point literal.
///
/// - Parameter value: The double value.
public init(_ value: Double) {
self.init(value as Any)
}

// Initializer for strings
/// Creates a new `Constant` expression from a string literal.
///
/// - Parameter value: The string value.
public init(_ value: String) {
self.init(value as Any)
}

// Initializer for boolean values
/// Creates a new `Constant` expression from a boolean literal.
///
/// - Parameter value: The boolean value.
public init(_ value: Bool) {
self.init(value as Any)
}

// Initializer for Bytes
/// Creates a new `Constant` expression from a `Data` (bytes) literal.
///
/// - Parameter value: The `Data` value.
public init(_ value: Data) {
self.init(value as Any)
}

// Initializer for GeoPoint values
/// Creates a new `Constant` expression from a `GeoPoint` literal.
///
/// - Parameter value: The `GeoPoint` value.
public init(_ value: GeoPoint) {
self.init(value as Any)
}

// Initializer for Timestamp values
/// Creates a new `Constant` expression from a `Timestamp` literal.
///
/// - Parameter value: The `Timestamp` value.
public init(_ value: Timestamp) {
self.init(value as Any)
}

// Initializer for Date values
/// Creates a new `Constant` expression from a `Date` literal.
///
/// The `Date` will be converted to a `Timestamp` internally.
///
/// - Parameter value: The `Date` value.
public init(_ value: Date) {
self.init(value as Any)
}

// Initializer for DocumentReference
/// Creates a new `Constant` expression from a `DocumentReference` literal.
///
/// - Parameter value: The `DocumentReference` value.
public init(_ value: DocumentReference) {
self.init(value as Any)
}

// Initializer for vector values
/// Creates a new `Constant` expression from a `VectorValue` literal.
///
/// - Parameter value: The `VectorValue` value.
public init(_ value: VectorValue) {
self.init(value as Any)
}

/// A `Constant` representing a `nil` value.
public static let `nil` = Constant(nil)
}
22 changes: 22 additions & 0 deletions Firestore/Swift/Source/SwiftAPI/Pipeline/Expressions/Field.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@
// See the License for the specific language governing permissions and
// limitations under the License.

///
/// A `Field` is an `Expression` that represents a field in a Firestore document.
///
/// It is a central component for building queries and transformations in Firestore pipelines.
/// A `Field` can be used to:
/// - Reference a document field by its name or `FieldPath`.
/// - Create complex `BooleanExpression`s for filtering in a `where` clause.
/// - Perform mathematical operations on numeric fields.
/// - Manipulate string and array fields.
///
/// Example of creating a `Field` and using it in a `where` clause:
/// ```swift
/// // Reference the "price" field in a document
/// let priceField = Field("price")
///
/// // Create a query to find products where the price is greater than 100
/// firestore.pipeline()
/// .collection("products")
/// .where(priceField.greaterThan(100))
/// ```
public struct Field: Expression, Selectable, BridgeWrapper, SelectableWrapper,
@unchecked Sendable {
let bridge: ExprBridge
Expand All @@ -24,13 +44,15 @@ public struct Field: Expression, Selectable, BridgeWrapper, SelectableWrapper,

public let fieldName: String

/// Creates a new `Field` expression from a field name.
public init(_ name: String) {
let fieldBridge = FieldBridge(name: name)
bridge = fieldBridge
fieldName = fieldBridge.field_name()
alias = fieldName
}

/// Creates a new `Field` expression from a `FieldPath`.
public init(_ path: FieldPath) {
let fieldBridge = FieldBridge(path: path)
bridge = fieldBridge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,22 @@
// See the License for the specific language governing permissions and
// limitations under the License.

///
/// A `RandomExpression` is a `FunctionExpression` that generates a random floating-point
/// number between 0.0 (inclusive) and 1.0 (exclusive).
///
/// This expression is useful when you need to introduce a random value into a pipeline,
/// for example, to randomly sample a subset of documents.
///
/// Example of using `RandomExpression` to sample documents:
/// ```swift
/// // Create a query to sample approximately 10% of the documents in a collection
/// firestore.pipeline()
/// .collection("users")
/// .where(RandomExpression().lessThan(0.1))
/// ```
public class RandomExpression: FunctionExpression, @unchecked Sendable {
/// Creates a new `RandomExpression` that generates a random number.
public init() {
super.init("rand", [])
}
Expand Down