@@ -47,7 +47,7 @@ use datafusion_physical_expr::expressions::Column;
4747use datafusion_physical_expr:: utils:: collect_columns;
4848use datafusion_physical_expr:: { EquivalenceProperties , LexOrdering , Partitioning } ;
4949
50- use futures:: { Future , FutureExt } ;
50+ use futures:: { stream , Future , FutureExt } ;
5151
5252pub mod exec;
5353
@@ -515,10 +515,78 @@ impl PartitionStream for TestPartitionStream {
515515 & self . schema
516516 }
517517 fn execute ( & self , _ctx : Arc < TaskContext > ) -> SendableRecordBatchStream {
518- let stream = futures :: stream:: iter ( self . batches . clone ( ) . into_iter ( ) . map ( Ok ) ) ;
518+ let stream = stream:: iter ( self . batches . clone ( ) . into_iter ( ) . map ( Ok ) ) ;
519519 Box :: pin ( RecordBatchStreamAdapter :: new (
520520 Arc :: clone ( & self . schema ) ,
521521 stream,
522522 ) )
523523 }
524524}
525+
526+ /// Returns an `ExecutionPlan` that return a stream which panics if it is ever polled.
527+ /// This can be used to test that execution plan implementations do not eagerly start
528+ /// processing data when `ExecutionPlan::execute is called`.
529+ pub fn panic_exec ( partitions : usize ) -> Arc < dyn ExecutionPlan > {
530+ let schema = Arc :: new ( Schema :: new ( vec ! [ Field :: new( "i" , DataType :: Int32 , true ) ] ) ) ;
531+ Arc :: new ( PanicExec :: new ( schema, partitions) )
532+ }
533+
534+ #[ derive( Debug ) ]
535+ struct PanicExec {
536+ properties : PlanProperties ,
537+ }
538+
539+ impl PanicExec {
540+ fn new ( schema : SchemaRef , partitions : usize ) -> Self {
541+ Self {
542+ properties : PlanProperties :: new (
543+ EquivalenceProperties :: new ( schema. clone ( ) ) ,
544+ Partitioning :: UnknownPartitioning ( partitions) ,
545+ EmissionType :: Incremental ,
546+ Boundedness :: Bounded ,
547+ ) ,
548+ }
549+ }
550+ }
551+
552+ impl DisplayAs for PanicExec {
553+ fn fmt_as ( & self , _: DisplayFormatType , f : & mut Formatter ) -> fmt:: Result {
554+ write ! ( f, "Panic" )
555+ }
556+ }
557+
558+ impl ExecutionPlan for PanicExec {
559+ fn name ( & self ) -> & str {
560+ "PanicExec"
561+ }
562+
563+ fn as_any ( & self ) -> & dyn Any {
564+ self
565+ }
566+
567+ fn properties ( & self ) -> & PlanProperties {
568+ & self . properties
569+ }
570+
571+ fn children ( & self ) -> Vec < & Arc < dyn ExecutionPlan > > {
572+ vec ! [ ]
573+ }
574+
575+ fn with_new_children (
576+ self : Arc < Self > ,
577+ _: Vec < Arc < dyn ExecutionPlan > > ,
578+ ) -> Result < Arc < dyn ExecutionPlan > > {
579+ Ok ( self . clone ( ) )
580+ }
581+
582+ fn execute (
583+ & self ,
584+ _: usize ,
585+ _: Arc < TaskContext > ,
586+ ) -> Result < SendableRecordBatchStream > {
587+ Ok ( Box :: pin ( RecordBatchStreamAdapter :: new (
588+ self . schema ( ) ,
589+ stream:: once ( async { panic ! ( ) } ) ,
590+ ) ) )
591+ }
592+ }
0 commit comments