close
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dev/release/post-08-rust.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ main() {

pushd "${SOURCE_TOP_DIR}/rust"
cargo publish --all-features -p adbc_core
cargo publish --all-features -p adbc_ffi
cargo publish --all-features -p adbc_driver_manager
cargo publish --all-features -p adbc_datafusion
cargo publish --all-features -p adbc_snowflake
popd

echo "Success! The released Cargo crates are available here:"
echo " https://crates.io/crates/adbc_core"
echo " https://crates.io/crates/adbc_driver_ffi"
echo " https://crates.io/crates/adbc_driver_manager"
echo " https://crates.io/crates/adbc_datafusion"
echo " https://crates.io/crates/adbc_snowflake"
}
Expand Down
13 changes: 13 additions & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# under the License.

[workspace]
members = ["core", "driver_manager", "driver/*"]
members = ["core", "driver_manager", "ffi", "driver/*"]
resolver = "2"

[workspace.package]
Expand All @@ -36,6 +36,7 @@ categories = ["database"]
[workspace.dependencies]
adbc_core = { path = "./core", version = "0.20.0" }
adbc_driver_manager = { path = "./driver_manager", version = "0.20.0" }
adbc_ffi = { path = "./ffi", version = "0.20.0" }
arrow-array = { version = ">=53.1.0, <57", default-features = false, features = [
"ffi",
] }
Expand Down
34 changes: 18 additions & 16 deletions rust/core/src/ffi/constants.rs → rust/core/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,27 @@
// specific language governing permissions and limitations
// under the License.

//! Constants defined in [`adbc.h`](https://github.com/apache/arrow-adbc/blob/main/c/include/arrow-adbc/adbc.h)

use std::os::raw::c_int;

use super::types::FFI_AdbcStatusCode;
use crate::error::AdbcStatusCode;

pub const ADBC_STATUS_OK: FFI_AdbcStatusCode = 0;
pub const ADBC_STATUS_UNKNOWN: FFI_AdbcStatusCode = 1;
pub const ADBC_STATUS_NOT_IMPLEMENTED: FFI_AdbcStatusCode = 2;
pub const ADBC_STATUS_NOT_FOUND: FFI_AdbcStatusCode = 3;
pub const ADBC_STATUS_ALREADY_EXISTS: FFI_AdbcStatusCode = 4;
pub const ADBC_STATUS_INVALID_ARGUMENT: FFI_AdbcStatusCode = 5;
pub const ADBC_STATUS_INVALID_STATE: FFI_AdbcStatusCode = 6;
pub const ADBC_STATUS_INVALID_DATA: FFI_AdbcStatusCode = 7;
pub const ADBC_STATUS_INTEGRITY: FFI_AdbcStatusCode = 8;
pub const ADBC_STATUS_INTERNAL: FFI_AdbcStatusCode = 9;
pub const ADBC_STATUS_IO: FFI_AdbcStatusCode = 10;
pub const ADBC_STATUS_CANCELLED: FFI_AdbcStatusCode = 11;
pub const ADBC_STATUS_TIMEOUT: FFI_AdbcStatusCode = 12;
pub const ADBC_STATUS_UNAUTHENTICATED: FFI_AdbcStatusCode = 13;
pub const ADBC_STATUS_UNAUTHORIZED: FFI_AdbcStatusCode = 14;
pub const ADBC_STATUS_OK: AdbcStatusCode = 0;
pub const ADBC_STATUS_UNKNOWN: AdbcStatusCode = 1;
pub const ADBC_STATUS_NOT_IMPLEMENTED: AdbcStatusCode = 2;
pub const ADBC_STATUS_NOT_FOUND: AdbcStatusCode = 3;
pub const ADBC_STATUS_ALREADY_EXISTS: AdbcStatusCode = 4;
pub const ADBC_STATUS_INVALID_ARGUMENT: AdbcStatusCode = 5;
pub const ADBC_STATUS_INVALID_STATE: AdbcStatusCode = 6;
pub const ADBC_STATUS_INVALID_DATA: AdbcStatusCode = 7;
pub const ADBC_STATUS_INTEGRITY: AdbcStatusCode = 8;
pub const ADBC_STATUS_INTERNAL: AdbcStatusCode = 9;
pub const ADBC_STATUS_IO: AdbcStatusCode = 10;
pub const ADBC_STATUS_CANCELLED: AdbcStatusCode = 11;
pub const ADBC_STATUS_TIMEOUT: AdbcStatusCode = 12;
pub const ADBC_STATUS_UNAUTHENTICATED: AdbcStatusCode = 13;
pub const ADBC_STATUS_UNAUTHORIZED: AdbcStatusCode = 14;

pub const ADBC_VERSION_1_0_0: c_int = 1_000_000;
pub const ADBC_VERSION_1_1_0: c_int = 1_001_000;
Expand Down
54 changes: 54 additions & 0 deletions rust/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ use std::{ffi::NulError, fmt::Display};

use arrow_schema::ArrowError;

use crate::constants;

pub type AdbcStatusCode = u8;
Comment thread
mbrobbel marked this conversation as resolved.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can't move this to the FFI crate because the TryFrom implementation has to be in this crate?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could move it and provide a TryInto impl?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you guessed, I got stuck after my first attempt to move FFI_AdbcStatusCode to adbc_ffi and had to restart by moving it to another module, just like the first commit in this PR (7ff5fb5).

I believe it's better to keep this in adbc_core for the following reasons:

  1. To implement TryFrom / From.
  2. It's referenced from the constants mod.
  3. This status code doesn't include FFI.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just return u8 on the FFI side. We only need u8 to AdbcStatus Into. Let's not have 2 layers of conversions for an enum.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I wrote in the comments below, I'm wondering if this should be placed in the constants mod since it's defined in adbc.h.
#3381 (comment)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me. I just don't want another layer of conversion/indirection.


/// Status of an operation.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Status {
Expand Down Expand Up @@ -153,3 +157,53 @@ impl From<std::ffi::IntoStringError> for Error {
error.into()
}
}

impl TryFrom<AdbcStatusCode> for Status {
type Error = Error;

fn try_from(value: AdbcStatusCode) -> Result<Self> {
match value {
constants::ADBC_STATUS_OK => Ok(Status::Ok),
constants::ADBC_STATUS_UNKNOWN => Ok(Status::Unknown),
constants::ADBC_STATUS_NOT_IMPLEMENTED => Ok(Status::NotImplemented),
constants::ADBC_STATUS_NOT_FOUND => Ok(Status::NotFound),
constants::ADBC_STATUS_ALREADY_EXISTS => Ok(Status::AlreadyExists),
constants::ADBC_STATUS_INVALID_ARGUMENT => Ok(Status::InvalidArguments),
constants::ADBC_STATUS_INVALID_STATE => Ok(Status::InvalidState),
constants::ADBC_STATUS_INVALID_DATA => Ok(Status::InvalidData),
constants::ADBC_STATUS_INTEGRITY => Ok(Status::Integrity),
constants::ADBC_STATUS_INTERNAL => Ok(Status::Internal),
constants::ADBC_STATUS_IO => Ok(Status::IO),
constants::ADBC_STATUS_CANCELLED => Ok(Status::Cancelled),
constants::ADBC_STATUS_TIMEOUT => Ok(Status::Timeout),
constants::ADBC_STATUS_UNAUTHENTICATED => Ok(Status::Unauthenticated),
constants::ADBC_STATUS_UNAUTHORIZED => Ok(Status::Unauthorized),
v => Err(Error::with_message_and_status(
format!("Unknown status code: {v}"),
Status::InvalidData,
)),
Comment thread
eitsupi marked this conversation as resolved.
}
}
}

impl From<Status> for AdbcStatusCode {
fn from(value: Status) -> Self {
match value {
Status::Ok => constants::ADBC_STATUS_OK,
Status::Unknown => constants::ADBC_STATUS_UNKNOWN,
Status::NotImplemented => constants::ADBC_STATUS_NOT_IMPLEMENTED,
Status::NotFound => constants::ADBC_STATUS_NOT_FOUND,
Status::AlreadyExists => constants::ADBC_STATUS_ALREADY_EXISTS,
Status::InvalidArguments => constants::ADBC_STATUS_INVALID_ARGUMENT,
Status::InvalidState => constants::ADBC_STATUS_INVALID_STATE,
Status::InvalidData => constants::ADBC_STATUS_INVALID_DATA,
Status::Integrity => constants::ADBC_STATUS_INTEGRITY,
Status::Internal => constants::ADBC_STATUS_INTERNAL,
Status::IO => constants::ADBC_STATUS_IO,
Status::Cancelled => constants::ADBC_STATUS_CANCELLED,
Status::Timeout => constants::ADBC_STATUS_TIMEOUT,
Status::Unauthenticated => constants::ADBC_STATUS_UNAUTHENTICATED,
Status::Unauthorized => constants::ADBC_STATUS_UNAUTHORIZED,
}
}
}
96 changes: 0 additions & 96 deletions rust/core/src/ffi/methods.rs

This file was deleted.

30 changes: 4 additions & 26 deletions rust/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@
//!
//! Read more about ADBC at <https://arrow.apache.org/adbc/>
//!
//! This library currently provides:
//! - An abstract Rust API to be implemented by vendor-specific drivers.
//! - A driver manager which implements this same API, but dynamically loads
//! drivers internally and forwards calls appropriately using the [C API](https://github.com/apache/arrow-adbc/blob/main/c/include/arrow-adbc/adbc.h).
//! - A driver exporter that takes an implementation of the abstract API and
//! turns it into an object file that implements the C API.
//! The `core` library currently provides the basic types shared by vendor-specific drivers,
//! the driver manager, and the driver exporter.
//!
//! # Native Rust drivers
//!
Expand All @@ -42,27 +38,9 @@
//!
//! For drivers implemented in Rust, using these will be more efficient and
//! safe, since it avoids the overhead of going through C FFI.
//!
//! # Driver Manager
//!
//! The [driver_manager] module allows loading drivers exposing the C API,
//! either from an initialization function (link-time, either static or dynamic)
//! or by dynamically finding such a function in a dynamic library (run-time).
//! The driver manager is gated behind the `driver_manager` feature flag.
//!
//! # Driver Exporter
//!
//! The driver exporter allows exposing native Rust drivers as C drivers to be
//! used by other languages via their own driver manager. Once you have an
//! implementation of [Driver], provided that it also implements [Default], you
//! can build it as an object file implementing the C API with the
//! [export_driver] macro.

mod driver_exporter;
#[doc(hidden)]
pub use driver_exporter::FFIDriver;

pub mod constants;
pub mod error;
pub mod ffi;
pub mod options;
pub mod schemas;

Expand Down
Loading
Loading