diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 91c94481d4..e1e62979df 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -159,6 +159,7 @@ dependencies = [ "arrow-schema", "chrono", "chrono-tz", + "futures", "half", "hashbrown 0.17.1", "num-complex", diff --git a/rust/core/Cargo.toml b/rust/core/Cargo.toml index bd33bf57f5..ddf296e9a1 100644 --- a/rust/core/Cargo.toml +++ b/rust/core/Cargo.toml @@ -32,6 +32,7 @@ version.workspace = true [features] default = [] +async = ["arrow-array/async"] [dependencies] arrow-array.workspace = true diff --git a/rust/core/src/lib.rs b/rust/core/src/lib.rs index 80485c9c26..f83582b6b0 100644 --- a/rust/core/src/lib.rs +++ b/rust/core/src/lib.rs @@ -45,6 +45,9 @@ pub mod options; pub mod schemas; pub mod sync; +#[cfg(feature = "async")] +pub mod nonblocking; + pub use sync::*; use arrow_schema::Schema; diff --git a/rust/core/src/nonblocking.rs b/rust/core/src/nonblocking.rs new file mode 100644 index 0000000000..73663e6707 --- /dev/null +++ b/rust/core/src/nonblocking.rs @@ -0,0 +1,521 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use arrow_array::RecordBatch; +use arrow_schema::Schema; + +use std::collections::HashSet; +use std::pin::Pin; + +use crate::error::Result; +use crate::options::*; + +/// Ability to configure an object by setting/getting options. +pub trait AsyncOptionable: Send { + type Option: AsRef + Send; + + /// Set a post-init option. + fn set_option( + &mut self, + key: Self::Option, + value: OptionValue, + ) -> impl std::future::Future> + Send; + + /// Get a string option value by key. + fn get_option_string( + &self, + key: Self::Option, + ) -> impl std::future::Future> + Send; + + /// Get a bytes option value by key. + fn get_option_bytes( + &self, + key: Self::Option, + ) -> impl std::future::Future>> + Send; + + /// Get an integer option value by key. + fn get_option_int( + &self, + key: Self::Option, + ) -> impl std::future::Future> + Send; + + /// Get a float option value by key. + fn get_option_double( + &self, + key: Self::Option, + ) -> impl std::future::Future> + Send; +} + +/// A handle to an async ADBC driver. +pub trait AsyncDriver: Send { + type DatabaseType: AsyncDatabase; + + /// Allocate and initialize a new database without pre-init options. + fn new_database( + &mut self, + ) -> impl std::future::Future> + Send; + + /// Allocate and initialize a new database with pre-init options. + fn new_database_with_opts( + &mut self, + opts: Vec<(OptionDatabase, OptionValue)>, + ) -> impl std::future::Future> + Send; +} + +/// A handle to an async 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 AsyncDatabase: AsyncOptionable