File tree Expand file tree Collapse file tree 4 files changed +26
-0
lines changed Expand file tree Collapse file tree 4 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -197,4 +197,9 @@ public actor DataFrame: Sendable {
197
197
let plan = SparkConnectClient . getProject ( self . plan. root, cols)
198
198
return DataFrame ( spark: self . spark, plan: plan)
199
199
}
200
+
201
+ public func limit( _ n: Int32 ) -> DataFrame {
202
+ let plan = SparkConnectClient . getLimit ( self . plan. root, n)
203
+ return DataFrame ( spark: self . spark, plan: plan)
204
+ }
200
205
}
Original file line number Diff line number Diff line change @@ -268,4 +268,15 @@ public actor SparkConnectClient {
268
268
plan. opType = . root( relation)
269
269
return plan
270
270
}
271
+
272
+ static func getLimit( _ child: Relation , _ n: Int32 ) -> Plan {
273
+ var limit = Limit ( )
274
+ limit. input = child
275
+ limit. limit = n
276
+ var relation = Relation ( )
277
+ relation. limit = limit
278
+ var plan = Plan ( )
279
+ plan. opType = . root( relation)
280
+ return plan
281
+ }
271
282
}
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ typealias ExecutePlanRequest = Spark_Connect_ExecutePlanRequest
24
24
typealias Plan = Spark_Connect_Plan
25
25
typealias Project = Spark_Connect_Project
26
26
typealias KeyValue = Spark_Connect_KeyValue
27
+ typealias Limit = Spark_Connect_Limit
27
28
typealias Range = Spark_Connect_Range
28
29
typealias Relation = Spark_Connect_Relation
29
30
typealias SparkConnectService = Spark_Connect_SparkConnectService
Original file line number Diff line number Diff line change @@ -107,6 +107,15 @@ struct DataFrameTests {
107
107
await spark. stop ( )
108
108
}
109
109
110
+ @Test
111
+ func limit( ) async throws {
112
+ let spark = try await SparkSession . builder. getOrCreate ( )
113
+ #expect( try await spark. range ( 10 ) . limit ( 0 ) . count ( ) == 0 )
114
+ #expect( try await spark. range ( 10 ) . limit ( 1 ) . count ( ) == 1 )
115
+ #expect( try await spark. range ( 10 ) . limit ( 2 ) . count ( ) == 2 )
116
+ await spark. stop ( )
117
+ }
118
+
110
119
@Test
111
120
func table( ) async throws {
112
121
let spark = try await SparkSession . builder. getOrCreate ( )
You can’t perform that action at this time.
0 commit comments