uqa_execution/statement/thread_context.rs
1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! The thread-local inputs and cancellation of one running statement, which the statement enters where it runs and each thread that runs part of it enters before that work.
8
9use super::thread_scope::StatementThreadScope;
10
11/// The temporal input a statement's expressions read and the cancellation work inside one scalar evaluation observes. A statement enters the context it runs under for its analysis, planning and execution; work dispatched to another thread captures the dispatching thread's context and enters it on that thread.
12#[derive(Clone)]
13pub struct StatementThreadContext {
14 pub temporal_input: uqa_sql::expr::TemporalInputContext,
15 /// The running statement's cancellation token, or `None` for work dispatched from outside any statement.
16 pub cancellation: Option<uqa_core::CancellationToken>,
17}
18
19impl StatementThreadContext {
20 /// Capture the invoking thread's context for work it dispatches to another thread.
21 #[must_use]
22 pub fn current() -> Self {
23 Self {
24 temporal_input: uqa_sql::expr::TemporalInputContext::current(),
25 cancellation: uqa_sql::expr::statement_cancellation(),
26 }
27 }
28
29 /// Run the invoking thread under this context until the returned scope drops, which restores the enclosing context.
30 #[must_use]
31 pub fn enter(&self) -> StatementThreadScope {
32 StatementThreadScope::enter(self)
33 }
34}