Skip to main content

robin_sparkless_expr/
udf_context.rs

1//! Thread-local UDF context for call_udf. Set by the main crate's SparkSession.
2
3use std::cell::RefCell;
4use std::sync::Arc;
5
6use crate::udf_registry::UdfRegistry;
7
8thread_local! {
9    static THREAD_UDF_CONTEXT: RefCell<Option<(Arc<UdfRegistry>, bool)>> = const { RefCell::new(None) };
10}
11
12/// Set the thread-local UDF context (registry + case_sensitive). Called by the main crate's session.
13pub fn set_thread_udf_context(registry: Arc<UdfRegistry>, case_sensitive: bool) {
14    THREAD_UDF_CONTEXT.with(|cell| *cell.borrow_mut() = Some((registry, case_sensitive)));
15}
16
17/// Get the thread-local UDF context for call_udf.
18pub fn get_thread_udf_context() -> Option<(Arc<UdfRegistry>, bool)> {
19    THREAD_UDF_CONTEXT.with(|cell| cell.borrow().clone())
20}