wjones127 commented on code in PR #478: URL: https://github.com/apache/arrow-adbc/pull/478#discussion_r1207210647
########## rust/src/lib.rs: ########## @@ -0,0 +1,380 @@ +// 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. + +//! Arrow Database Connectivity (ADBC) allows efficient connections to databases +//! for OLAP workloads: +//! +//! * Uses the Arrow [C Data interface](https://arrow.apache.org/docs/format/CDataInterface.html) +//! and [C Stream Interface](https://arrow.apache.org/docs/format/CStreamInterface.html) +//! for efficient data interchange. +//! * Supports partitioned result sets for multi-threaded or distributed +//! applications. +//! * Support for [Substrait](https://substrait.io/) plans in addition to SQL queries. +//! +//! When implemented for remote databases, [Flight SQL](https://arrow.apache.org/docs/format/FlightSql.html) +//! can be used as the communication protocol. This means data can be in Arrow +//! format through the whole connection, minimizing serialization and deserialization +//! overhead. +//! +//! Read more about ADBC at <https://arrow.apache.org/adbc/> +//! +//! There are two flavors of ADBC that this library supports: +//! +//! * **Native Rust implementations**. These implement the traits at the top level of +//! this crate, starting with [AdbcDatabase]. +//! * **C API ADBC drivers**. These can be implemented in any language (that compiles +//! to native code) and can be used by any language. +//! +//! # Native Rust drivers +//! +//! Native Rust drivers will implement the traits: +//! +//! * [AdbcDatabase] +//! * [AdbcConnection] +//! * [AdbcStatement] +//! +//! For drivers implemented in Rust, using these will be more efficient and safe, +//! since it avoids the overhead of going through C FFI. +//! +//! # Using C API drivers +//! +//! 🚧 TODO +//! +//! # Creating C API drivers +//! +//! 🚧 TODO +//! +pub mod error; +pub mod info; +pub mod objects; + +use arrow_array::{RecordBatch, RecordBatchReader}; +use arrow_schema::Schema; + +use crate::error::AdbcError; +use crate::info::InfoData; + +/// 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. +pub trait AdbcDatabase { + type ConnectionType: AdbcConnection; + + /// Set an option on the database. + /// + /// Some databases may not allow setting options after it has been initialized. + fn set_option(&self, key: &str, value: &str) -> Result<(), AdbcError>; + + /// Initialize a connection to the database. + /// + /// `options` provided will configure the connection, including the isolation + /// level. See standard options in [options]. + fn connect<K, V>( + &self, + options: impl IntoIterator<Item = (K, V)>, + ) -> Result<Self::ConnectionType, AdbcError> + where + K: AsRef<str>, + V: AsRef<str>; +} + +/// A connection is a single connection to a database. +/// +/// It is never accessed concurrently from multiple threads. +/// +/// # Autocommit +/// +/// Connections should start in autocommit mode. They can be moved out by +/// setting `"adbc.connection.autocommit"` to `"false"` (using +/// [AdbcConnection::set_option]). Turning off autocommit allows customizing +/// the isolation level. Read more in [adbc.h](https://github.com/apache/arrow-adbc/blob/main/adbc.h). +pub trait AdbcConnection { Review Comment: At least the parts of the Arrow community I've seen, async is always preferred. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
