1616// under the License.
1717
1818use std:: any:: Any ;
19- use std:: pin:: Pin ;
2019use std:: sync:: Arc ;
2120
22- use datafusion:: arrow:: array:: RecordBatch ;
2321use datafusion:: arrow:: datatypes:: SchemaRef as ArrowSchemaRef ;
2422use datafusion:: error:: Result as DFResult ;
2523use datafusion:: execution:: { SendableRecordBatchStream , TaskContext } ;
2624use datafusion:: physical_expr:: EquivalenceProperties ;
2725use datafusion:: physical_plan:: execution_plan:: { Boundedness , EmissionType } ;
2826use datafusion:: physical_plan:: stream:: RecordBatchStreamAdapter ;
2927use datafusion:: physical_plan:: { DisplayAs , ExecutionPlan , Partitioning , PlanProperties } ;
30- use futures:: { Stream , StreamExt , TryStreamExt } ;
28+ use futures:: { StreamExt , TryStreamExt } ;
3129use paimon:: table:: Table ;
3230use paimon:: DataSplit ;
3331
@@ -128,7 +126,6 @@ impl ExecutionPlan for PaimonTableScan {
128126 let table = self . table . clone ( ) ;
129127 let schema = self . schema ( ) ;
130128 let projected_columns = self . projected_columns . clone ( ) ;
131- let limit = self . limit ;
132129
133130 let fut = async move {
134131 let mut read_builder = table. new_read_builder ( ) ;
@@ -148,31 +145,9 @@ impl ExecutionPlan for PaimonTableScan {
148145 ) )
149146 } ;
150147
151- let stream = futures:: stream:: once ( fut) . try_flatten ( ) ;
152-
153- // Enforce the final LIMIT at the DataFusion execution layer.
154- let limited_stream: Pin < Box < dyn Stream < Item = DFResult < RecordBatch > > + Send > > =
155- if let Some ( limit) = limit {
156- let mut remaining = limit;
157- Box :: pin ( stream. try_filter_map ( move |batch| {
158- futures:: future:: ready ( if remaining == 0 {
159- Ok ( None )
160- } else if batch. num_rows ( ) <= remaining {
161- remaining -= batch. num_rows ( ) ;
162- Ok ( Some ( batch) )
163- } else {
164- let limited_batch = batch. slice ( 0 , remaining) ;
165- remaining = 0 ;
166- Ok ( Some ( limited_batch) )
167- } )
168- } ) )
169- } else {
170- Box :: pin ( stream)
171- } ;
172-
173148 Ok ( Box :: pin ( RecordBatchStreamAdapter :: new (
174149 self . schema ( ) ,
175- limited_stream ,
150+ futures :: stream :: once ( fut ) . try_flatten ( ) ,
176151 ) ) )
177152 }
178153}
0 commit comments