Skip to content

Commit bfaf8db

Browse files
committed
wire duckdb
Signed-off-by: Onur Satici <[email protected]>
1 parent 6dafd16 commit bfaf8db

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

vortex-duckdb/src/lib.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
use std::ffi::CStr;
77
use std::ffi::c_char;
88
use std::sync::LazyLock;
9+
use std::sync::OnceLock;
910

1011
use vortex::VortexSessionDefault;
1112
use vortex::error::VortexExpect;
1213
use vortex::error::VortexResult;
1314
use vortex::io::runtime::BlockingRuntime;
1415
use vortex::io::runtime::current::CurrentThreadRuntime;
16+
use vortex::io::runtime::Handle;
1517
use vortex::io::session::RuntimeSessionExt;
1618
use vortex::session::VortexSession;
1719

@@ -40,9 +42,22 @@ mod copy;
4042
mod e2e_test;
4143

4244
// 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+
}
4661

4762
/// Register Vortex extension configuration options with DuckDB.
4863
/// This must be called before `register_table_functions` to take effect.

0 commit comments

Comments
 (0)