MCPcopy Create free account
hub / github.com/apache/datafusion / stream_yields

Function stream_yields

datafusion/core/tests/execution/coop.rs:774–820  ·  view source on GitHub ↗
(
    mut stream: SendableRecordBatchStream,
)

Source from the content-addressed store, hash-verified

772}
773
774async fn stream_yields(
775 mut stream: SendableRecordBatchStream,
776) -> Result<(), Box<dyn Error>> {
777 // Create an independent executor pool
778 let child_runtime = Runtime::new()?;
779
780 // Spawn a task that tries to poll the stream
781 // The task returns Ready when the stream yielded with either Ready or Pending
782 let join_handle = child_runtime.spawn(std::future::poll_fn(move |cx| {
783 match stream.poll_next_unpin(cx) {
784 Poll::Ready(Some(Ok(_))) => Poll::Ready(Poll::Ready(Ok(()))),
785 Poll::Ready(Some(Err(e))) => Poll::Ready(Poll::Ready(Err(e))),
786 Poll::Ready(None) => Poll::Ready(Poll::Ready(Ok(()))),
787 Poll::Pending => Poll::Ready(Poll::Pending),
788 }
789 }));
790
791 let abort_handle = join_handle.abort_handle();
792
793 // Now select on the join handle of the task running in the child executor with a timeout
794 let yielded = select! {
795 result = join_handle => {
796 match result {
797 Ok(Poll::Pending) => Yielded::ReadyOrPending,
798 Ok(Poll::Ready(Ok(_))) => Yielded::ReadyOrPending,
799 Ok(Poll::Ready(Err(e))) => Yielded::Err(e),
800 Err(_) => Yielded::Err(exec_datafusion_err!("join error")),
801 }
802 },
803 _ = tokio::time::sleep(Duration::from_secs(10)) => {
804 Yielded::Timeout
805 }
806 };
807
808 // Try to abort the poll task and shutdown the child runtime
809 abort_handle.abort();
810 Handle::current().spawn_blocking(move || {
811 child_runtime.shutdown_timeout(Duration::from_secs(5));
812 });
813
814 // Finally, check if poll_next yielded
815 assert!(
816 matches!(yielded, Yielded::ReadyOrPending),
817 "Result is not Ready or Pending: {yielded:?}"
818 );
819 Ok(())
820}
821
822async fn query_yields(
823 plan: Arc<dyn ExecutionPlan>,

Callers 2

query_yieldsFunction · 0.85

Calls 3

newFunction · 0.85
spawnMethod · 0.45
spawn_blockingMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…