@@ -2008,8 +2008,8 @@ class PipelineIntegrationTests: FSTIntegrationTestCase {
2008
2008
. select (
2009
2009
Field ( " rating " ) . isNull ( ) . as ( " ratingIsNull " ) ,
2010
2010
Field ( " rating " ) . isNan ( ) . as ( " ratingIsNaN " ) ,
2011
- Field ( " title " ) . arrayOffset ( 0 ) . isError ( ) . as ( " isError " ) ,
2012
- Field ( " title " ) . arrayOffset ( 0 ) . ifError ( Constant ( " was error " ) ) . as ( " ifError " ) ,
2011
+ Field ( " title " ) . arrayGet ( 0 ) . isError ( ) . as ( " isError " ) ,
2012
+ Field ( " title " ) . arrayGet ( 0 ) . ifError ( Constant ( " was error " ) ) . as ( " ifError " ) ,
2013
2013
Field ( " foo " ) . isAbsent ( ) . as ( " isAbsent " ) ,
2014
2014
Field ( " title " ) . isNotNull ( ) . as ( " titleIsNotNull " ) ,
2015
2015
Field ( " cost " ) . isNotNan ( ) . as ( " costIsNotNan " ) ,
@@ -2045,8 +2045,8 @@ class PipelineIntegrationTests: FSTIntegrationTestCase {
2045
2045
. select (
2046
2046
Field ( " rating " ) . isNull ( ) . as ( " ratingIsNull " ) ,
2047
2047
Field ( " rating " ) . isNan ( ) . as ( " ratingIsNaN " ) ,
2048
- Field ( " title " ) . arrayOffset ( 0 ) . isError ( ) . as ( " isError " ) ,
2049
- Field ( " title " ) . arrayOffset ( 0 ) . ifError ( Constant ( " was error " ) ) . as ( " ifError " ) ,
2048
+ Field ( " title " ) . arrayGet ( 0 ) . isError ( ) . as ( " isError " ) ,
2049
+ Field ( " title " ) . arrayGet ( 0 ) . ifError ( Constant ( " was error " ) ) . as ( " ifError " ) ,
2050
2050
Field ( " foo " ) . isAbsent ( ) . as ( " isAbsent " ) ,
2051
2051
Field ( " title " ) . isNotNull ( ) . as ( " titleIsNotNull " ) ,
2052
2052
Field ( " cost " ) . isNotNan ( ) . as ( " costIsNotNan " )
@@ -2452,18 +2452,16 @@ class PipelineIntegrationTests: FSTIntegrationTestCase {
2452
2452
let collRef = collectionRef ( withDocuments: bookDocs)
2453
2453
2454
2454
let expectedResultsPart1 : [ [ String : Sendable ? ] ] = [
2455
- [ " firstTag " : " adventure " ] , // book4 (rating 4.7)
2456
- [ " firstTag " : " politics " ] , // book10 (rating 4.6)
2457
- [ " firstTag " : " classic " ] , // book2 (rating 4.5)
2455
+ [ " firstTag " : " adventure " ] ,
2456
+ [ " firstTag " : " politics " ] ,
2457
+ [ " firstTag " : " classic " ] ,
2458
2458
]
2459
2459
2460
- // Part 1: Using arrayOffset as FunctionExpr("array_offset", ...)
2461
- // (Assuming direct top-level ArrayOffset() isn't available, as per Expr.swift structure)
2462
2460
let pipeline1 = db. pipeline ( )
2463
2461
. collection ( collRef. path)
2464
2462
. sort ( Field ( " rating " ) . descending ( ) )
2465
2463
. limit ( 3 )
2466
- . select ( Field ( " tags " ) . arrayOffset ( 0 ) . as ( " firstTag " ) )
2464
+ . select ( Field ( " tags " ) . arrayGet ( 0 ) . as ( " firstTag " ) )
2467
2465
2468
2466
let snapshot1 = try await pipeline1. execute ( )
2469
2467
XCTAssertEqual ( snapshot1. results. count, 3 , " Part 1: Should retrieve three documents " )
@@ -3039,4 +3037,129 @@ class PipelineIntegrationTests: FSTIntegrationTestCase {
3039
3037
enforceOrder: false
3040
3038
)
3041
3039
}
3040
+
3041
+ private func addBooks( to collectionReference: CollectionReference ) async throws {
3042
+ try await collectionReference. document ( " book11 " ) . setData ( [
3043
+ " title " : " Jonathan Strange & Mr Norrell " ,
3044
+ " author " : " Susanna Clarke " ,
3045
+ " genre " : " Fantasy " ,
3046
+ " published " : 2004 ,
3047
+ " rating " : 4.6 ,
3048
+ " tags " : [ " historical fantasy " , " magic " , " alternate history " , " england " ] ,
3049
+ " awards " : [ " hugo " : false , " nebula " : false ] ,
3050
+ ] )
3051
+ try await collectionReference. document ( " book12 " ) . setData ( [
3052
+ " title " : " The Master and Margarita " ,
3053
+ " author " : " Mikhail Bulgakov " ,
3054
+ " genre " : " Satire " ,
3055
+ " published " : 1967 ,
3056
+ " rating " : 4.6 ,
3057
+ " tags " : [ " russian literature " , " supernatural " , " philosophy " , " dark comedy " ] ,
3058
+ " awards " : [ : ] ,
3059
+ ] )
3060
+ try await collectionReference. document ( " book13 " ) . setData ( [
3061
+ " title " : " A Long Way to a Small, Angry Planet " ,
3062
+ " author " : " Becky Chambers " ,
3063
+ " genre " : " Science Fiction " ,
3064
+ " published " : 2014 ,
3065
+ " rating " : 4.6 ,
3066
+ " tags " : [ " space opera " , " found family " , " character-driven " , " optimistic " ] ,
3067
+ " awards " : [ " hugo " : false , " nebula " : false , " kitschies " : true ] ,
3068
+ ] )
3069
+ }
3070
+
3071
+ func testSupportsPaginationWithOffsetsUsingName( ) async throws {
3072
+ try XCTSkipIf ( true , " Skip this test since backend has not yet supported. " )
3073
+
3074
+ let collRef = collectionRef ( withDocuments: bookDocs)
3075
+ let db = collRef. firestore
3076
+ try await addBooks ( to: collRef)
3077
+
3078
+ let pageSize = 2
3079
+
3080
+ let pipeline = db. pipeline ( )
3081
+ . collection ( collRef. path)
3082
+ . select ( " title " , " rating " , " __name__ " )
3083
+ . sort (
3084
+ Field ( " rating " ) . descending ( ) ,
3085
+ Field ( " __name__ " ) . ascending ( )
3086
+ )
3087
+
3088
+ var snapshot = try await pipeline. limit ( Int32 ( pageSize) ) . execute ( )
3089
+
3090
+ TestHelper . compare (
3091
+ pipelineSnapshot: snapshot,
3092
+ expected: [
3093
+ [ " title " : " The Lord of the Rings " , " rating " : 4.7 ] ,
3094
+ [ " title " : " Jonathan Strange & Mr Norrell " , " rating " : 4.6 ] ,
3095
+ ] ,
3096
+ enforceOrder: true
3097
+ )
3098
+
3099
+ let lastDoc = snapshot. results. last!
3100
+
3101
+ snapshot = try await pipeline. where (
3102
+ ( Field ( " rating " ) . eq ( lastDoc. get ( " rating " ) !)
3103
+ && Field ( " rating " ) . lt ( lastDoc. get ( " rating " ) !) )
3104
+ || Field ( " rating " ) . lt ( lastDoc. get ( " rating " ) !)
3105
+ ) . limit ( Int32 ( pageSize) ) . execute ( )
3106
+
3107
+ TestHelper . compare (
3108
+ pipelineSnapshot: snapshot,
3109
+ expected: [
3110
+ [ " title " : " Pride and Prejudice " , " rating " : 4.5 ] ,
3111
+ [ " title " : " Crime and Punishment " , " rating " : 4.3 ] ,
3112
+ ] ,
3113
+ enforceOrder: false
3114
+ )
3115
+ }
3116
+
3117
+ func testSupportsPaginationWithOffsetsUsingPath( ) async throws {
3118
+ try XCTSkipIf ( true , " Skip this test since backend has not yet supported. " )
3119
+
3120
+ let collRef = collectionRef ( withDocuments: bookDocs)
3121
+ let db = collRef. firestore
3122
+ try await addBooks ( to: collRef)
3123
+
3124
+ let pageSize = 2
3125
+ var currPage = 0
3126
+
3127
+ let pipeline = db. pipeline ( )
3128
+ . collection ( collRef. path)
3129
+ . select ( " title " , " rating " , " __path__ " )
3130
+ . sort (
3131
+ Field ( " rating " ) . descending ( ) ,
3132
+ Field ( " __path__ " ) . ascending ( )
3133
+ )
3134
+
3135
+ var snapshot = try await pipeline. offset ( Int32 ( currPage) * Int32( pageSize) ) . limit (
3136
+ Int32 ( pageSize)
3137
+ ) . execute ( )
3138
+
3139
+ currPage += 1
3140
+
3141
+ TestHelper . compare (
3142
+ pipelineSnapshot: snapshot,
3143
+ expected: [
3144
+ [ " title " : " The Lord of the Rings " , " rating " : 4.7 ] ,
3145
+ [ " title " : " Dune " , " rating " : 4.6 ] ,
3146
+ ] ,
3147
+ enforceOrder: true
3148
+ )
3149
+
3150
+ snapshot = try await pipeline. offset ( Int32 ( currPage) * Int32( pageSize) ) . limit (
3151
+ Int32 ( pageSize)
3152
+ ) . execute ( )
3153
+
3154
+ currPage += 1
3155
+
3156
+ TestHelper . compare (
3157
+ pipelineSnapshot: snapshot,
3158
+ expected: [
3159
+ [ " title " : " A Long Way to a Small, Angry Planet " , " rating " : 4.6 ] ,
3160
+ [ " title " : " Pride and Prejudice " , " rating " : 4.5 ] ,
3161
+ ] ,
3162
+ enforceOrder: true
3163
+ )
3164
+ }
3042
3165
}
0 commit comments