diff --git a/rust/Cargo.lock b/rust/Cargo.lock index e8070b5dc3..0fc7638fb6 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -8,6 +8,7 @@ version = "0.22.0" dependencies = [ "arrow-array", "arrow-schema", + "futures", ] [[package]] @@ -22,6 +23,7 @@ dependencies = [ "arrow-select", "datafusion", "datafusion-substrait", + "futures", "prost", "tokio", ] @@ -40,7 +42,7 @@ dependencies = [ "tempfile", "toml", "windows-registry", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 644769716d..2afbf9bc88 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -43,3 +43,4 @@ arrow-array = { version = ">=53.1.0, <58", default-features = false, features = arrow-buffer = { version = ">=53.1.0, <58", default-features = false } arrow-schema = { version = ">=53.1.0, <58", default-features = false } arrow-select = { version = ">=53.1.0, <58", default-features = false } +futures = "0.3" diff --git a/rust/core/Cargo.toml b/rust/core/Cargo.toml index bd33bf57f5..ab17a68a91 100644 --- a/rust/core/Cargo.toml +++ b/rust/core/Cargo.toml @@ -36,6 +36,7 @@ default = [] [dependencies] arrow-array.workspace = true arrow-schema.workspace = true +futures.workspace = true [package.metadata.docs.rs] all-features = true diff --git a/rust/core/src/lib.rs b/rust/core/src/lib.rs index c8df8a9c18..36bbe10c46 100644 --- a/rust/core/src/lib.rs +++ b/rust/core/src/lib.rs @@ -31,26 +31,38 @@ //! # Native Rust drivers //! //! Native Rust drivers will implement the abstract API consisting of the traits: +//! //! - [Driver] //! - [Database] //! - [Connection] //! - [Statement] //! +//! or async traits: +//! +//! - [crate::non_blocking::AsyncDriver] +//! - [crate::non_blocking::AsyncDatabase] +//! - [crate::non_blocking::AsyncConnection] +//! - [crate::non_blocking::AsyncStatement] +//! +//! or async traits that doesn't require Send bound: +//! +//! - [crate::non_blocking::LocalAsyncDriver] +//! - [crate::non_blocking::LocalAsyncDatabase] +//! - [crate::non_blocking::LocalAsyncConnection] +//! - [crate::non_blocking::LocalAsyncStatement] +//! //! For drivers implemented in Rust, using these will be more efficient and //! safe, since it avoids the overhead of going through C FFI. pub mod constants; pub mod error; +pub mod non_blocking; pub mod options; pub mod schemas; +pub mod sync; +pub mod syncify; -use std::collections::HashSet; - -use arrow_array::{RecordBatch, RecordBatchReader}; -use arrow_schema::Schema; - -use error::Result; -use options::{OptionConnection, OptionDatabase, OptionStatement, OptionValue}; +pub use sync::*; pub type LoadFlags = u32; @@ -63,459 +75,17 @@ pub const LOAD_FLAG_DEFAULT: LoadFlags = LOAD_FLAG_SEARCH_ENV | LOAD_FLAG_SEARCH_SYSTEM | LOAD_FLAG_ALLOW_RELATIVE_PATHS; -/// Ability to configure an object by setting/getting options. -pub trait Optionable { - type Option: AsRef; - - /// Set a post-init option. - fn set_option(&mut self, key: Self::Option, value: OptionValue) -> Result<()>; - - /// Get a string option value by key. - fn get_option_string(&self, key: Self::Option) -> Result; - - /// Get a bytes option value by key. - fn get_option_bytes(&self, key: Self::Option) -> Result>; - - /// Get an integer option value by key. - fn get_option_int(&self, key: Self::Option) -> Result; - - /// Get a float option value by key. - fn get_option_double(&self, key: Self::Option) -> Result; -} - -/// A handle to an ADBC driver. -pub trait Driver { - type DatabaseType: Database; - - /// Allocate and initialize a new database without pre-init options. - fn new_database(&mut self) -> Result; - - /// Allocate and initialize a new database with pre-init options. - fn new_database_with_opts( - &mut self, - opts: impl IntoIterator, - ) -> Result; -} - -/// A handle to an ADBC database. -/// -/// Databases hold state shared by multiple connections. This typically means -/// configuration and caches. For in-memory databases, it provides a place to -/// hold ownership of the in-memory database. -/// -/// Databases must be kept alive as long as any connections exist. -pub trait Database: Optionable