zhuqi-lucas commented on PR #16196:
URL: https://github.com/apache/datafusion/pull/16196#issuecomment-2922801898

   > Would this require any changes to `SessionContext`? Cancellation is per 
query, so I think you would want to add the `cancelled: AtomicBoolean`, `fn 
cancel()` and `fn is_cancelled() -> bool` methods to `TaskContext`.
   
   Because:
   
   1. It related to more use cases for example the datafusion-cli:
   ```rust
                         tokio::select! {
                           res = exec_and_print(ctx, print_options, line) => 
match res {
                               Ok(_) => {}
                               Err(err) => eprintln!("{err}"),
                           },
                           _ = signal::ctrl_c() => {
                               println!("^C");
                               continue
                           },
                       }
   
   ...                    
   #[async_trait::async_trait]
   impl CliSessionContext for SessionContext {
       fn task_ctx(&self) -> Arc<TaskContext> {
           self.task_ctx()
       }
   ```
   
   2. SessionContext also response the TaskContext:
   
   ```rust
    /// Get a new TaskContext to run in this session
       pub fn task_ctx(&self) -> Arc<TaskContext> {
           Arc::new(TaskContext::from(self))
       }
   
   /// Create a new task context instance from SessionContext
   impl From<&SessionContext> for TaskContext {
       fn from(session: &SessionContext) -> Self {
           TaskContext::from(&*session.state.read())
       }
   }
   
   /// Create a new task context instance from SessionState
   impl From<&SessionState> for TaskContext {
       fn from(state: &SessionState) -> Self {
           let task_id = None;
           TaskContext::new(
               task_id,
               state.session_id.clone(),
               state.config.clone(),
               state.scalar_functions.clone(),
               state.aggregate_functions.clone(),
               state.window_functions.clone(),
               Arc::clone(&state.runtime_env),
           )
       }
   }
   
   ```
   
   I think need some work, i will try it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to