File tree Expand file tree Collapse file tree 3 files changed +42
-2
lines changed
SwiftAPI/Pipeline/Expressions Expand file tree Collapse file tree 3 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -292,6 +292,10 @@ public extension Expression {
292
292
return FunctionExpression ( " floor " , [ self ] )
293
293
}
294
294
295
+ func ln( ) -> FunctionExpression {
296
+ return FunctionExpression ( " ln " , [ self ] )
297
+ }
298
+
295
299
func exp( ) -> FunctionExpression {
296
300
return FunctionExpression ( " exp " , [ self ] )
297
301
}
Original file line number Diff line number Diff line change @@ -36,7 +36,17 @@ public protocol Expression: Sendable {
36
36
37
37
// --- Added Mathematical Operations ---
38
38
39
- /// Creates an expression that returns the largest numeric value that isn't greater than X.
39
+ /// Creates an expression that returns the natural logarithm of self.
40
+ ///
41
+ /// ```swift
42
+ /// // Get the natural logarithm of the "amount" field.
43
+ /// Field("amount").ln()
44
+ /// ```
45
+ ///
46
+ /// - Returns: A new `FunctionExpression` representing the natural logarithm of the number.
47
+ func ln( ) -> FunctionExpression
48
+
49
+ /// Creates an expression that returns the largest numeric value that isn't greater than self.
40
50
///
41
51
/// ```swift
42
52
/// // Get the floor of the "amount" field.
@@ -46,7 +56,7 @@ public protocol Expression: Sendable {
46
56
/// - Returns: A new `FunctionExpression` representing the floor of the number.
47
57
func floor( ) -> FunctionExpression
48
58
49
- /// Creates an expression that returns e to the power of X .
59
+ /// Creates an expression that returns e to the power of self .
50
60
///
51
61
/// Returns zero on underflow and nil on overflow.
52
62
///
Original file line number Diff line number Diff line change @@ -2104,6 +2104,32 @@ class PipelineIntegrationTests: FSTIntegrationTestCase {
2104
2104
TestHelper . compare ( pipelineSnapshot: snapshot, expected: expectedResults, enforceOrder: true )
2105
2105
}
2106
2106
2107
+ func testLnWorks( ) async throws {
2108
+ let collRef = collectionRef ( withDocuments: [
2109
+ " doc1 " : [ " value " : 1 ] ,
2110
+ " doc2 " : [ " value " : exp ( Double ( 2 ) ) ] ,
2111
+ " doc3 " : [ " value " : exp ( Double ( 1 ) ) ] ,
2112
+ ] )
2113
+ let db = collRef. firestore
2114
+
2115
+ let pipeline = db. pipeline ( )
2116
+ . collection ( collRef. path)
2117
+ . select ( [
2118
+ Field ( " value " ) . ln ( ) . as ( " lnValue " ) ,
2119
+ ] )
2120
+ . sort ( [ Field ( " lnValue " ) . ascending ( ) ] )
2121
+
2122
+ let snapshot = try await pipeline. execute ( )
2123
+
2124
+ let expectedResults : [ [ String : Sendable ] ] = [
2125
+ [ " lnValue " : 0 ] ,
2126
+ [ " lnValue " : 1 ] ,
2127
+ [ " lnValue " : 2 ] ,
2128
+ ]
2129
+
2130
+ TestHelper . compare ( pipelineSnapshot: snapshot, expected: expectedResults, enforceOrder: true )
2131
+ }
2132
+
2107
2133
func testExpWorks( ) async throws {
2108
2134
let collRef = collectionRef ( withDocuments: [
2109
2135
" doc1 " : [ " value " : 1 ] ,
You can’t perform that action at this time.
0 commit comments