|
6 | 6 | use std::ffi::CStr; |
7 | 7 | use std::ffi::c_char; |
8 | 8 | use std::sync::LazyLock; |
| 9 | +use std::sync::OnceLock; |
9 | 10 |
|
10 | 11 | use vortex::VortexSessionDefault; |
11 | 12 | use vortex::error::VortexExpect; |
12 | 13 | use vortex::error::VortexResult; |
13 | 14 | use vortex::io::runtime::BlockingRuntime; |
14 | 15 | use vortex::io::runtime::current::CurrentThreadRuntime; |
| 16 | +use vortex::io::runtime::Handle; |
15 | 17 | use vortex::io::session::RuntimeSessionExt; |
16 | 18 | use vortex::session::VortexSession; |
17 | 19 |
|
@@ -40,9 +42,22 @@ mod copy; |
40 | 42 | mod e2e_test; |
41 | 43 |
|
42 | 44 | // A global runtime for Vortex operations within DuckDB. |
43 | | -static RUNTIME: LazyLock<CurrentThreadRuntime> = LazyLock::new(CurrentThreadRuntime::new); |
44 | | -static SESSION: LazyLock<VortexSession> = |
45 | | - LazyLock::new(|| VortexSession::default().with_handle(RUNTIME.handle())); |
| 45 | +static DEFAULT_RUNTIME: LazyLock<CurrentThreadRuntime> = LazyLock::new(CurrentThreadRuntime::new); |
| 46 | +static RUNTIME_OVERRIDE: OnceLock<Handle> = OnceLock::new(); |
| 47 | +static SESSION: LazyLock<VortexSession> = LazyLock::new(|| { |
| 48 | + let handle = RUNTIME_OVERRIDE |
| 49 | + .get() |
| 50 | + .cloned() |
| 51 | + .unwrap_or_else(|| DEFAULT_RUNTIME.handle()); |
| 52 | + VortexSession::default().with_handle(handle) |
| 53 | +}); |
| 54 | + |
| 55 | +/// Configure the runtime handle used by the DuckDB extension. |
| 56 | +/// |
| 57 | +/// Must be called before the session is first accessed (e.g., before registering table functions). |
| 58 | +pub fn configure_runtime(handle: Handle) { |
| 59 | + let _ = RUNTIME_OVERRIDE.set(handle); |
| 60 | +} |
46 | 61 |
|
47 | 62 | /// Register Vortex extension configuration options with DuckDB. |
48 | 63 | /// This must be called before `register_table_functions` to take effect. |
|
0 commit comments