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 {
197197 let plan = SparkConnectClient . getProject ( self . plan. root, cols)
198198 return DataFrame ( spark: self . spark, plan: plan)
199199 }
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+ }
200205}
Original file line number Diff line number Diff line change @@ -268,4 +268,15 @@ public actor SparkConnectClient {
268268 plan. opType = . root( relation)
269269 return plan
270270 }
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+ }
271282}
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ typealias ExecutePlanRequest = Spark_Connect_ExecutePlanRequest
2424typealias Plan = Spark_Connect_Plan
2525typealias Project = Spark_Connect_Project
2626typealias KeyValue = Spark_Connect_KeyValue
27+ typealias Limit = Spark_Connect_Limit
2728typealias Range = Spark_Connect_Range
2829typealias Relation = Spark_Connect_Relation
2930typealias SparkConnectService = Spark_Connect_SparkConnectService
Original file line number Diff line number Diff line change @@ -107,6 +107,15 @@ struct DataFrameTests {
107107 await spark. stop ( )
108108 }
109109
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+
110119 @Test
111120 func table( ) async throws {
112121 let spark = try await SparkSession . builder. getOrCreate ( )
You can’t perform that action at this time.
0 commit comments