Skip to content
Open
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
2 changes: 2 additions & 0 deletions rust/Cargo.lock

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

9 changes: 5 additions & 4 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ categories = ["database"]
adbc_core = { path = "./core", version = "0.26.0" }
adbc_driver_manager = { path = "./driver_manager", version = "0.26.0" }
adbc_ffi = { path = "./ffi", version = "0.26.0" }
arrow-array = { version = ">=58, <61", default-features = false, features = [
arrow-array = { version = ">=59, <61", default-features = false, features = [
"ffi",
] }
arrow-buffer = { version = ">=58, <61", default-features = false }
arrow-schema = { version = ">=58, <61", default-features = false }
arrow-select = { version = ">=58, <61", default-features = false }
arrow-buffer = { version = ">=59, <61", default-features = false }
arrow-data = { version = ">=59, <61", default-features = false }
arrow-schema = { version = ">=59, <61", default-features = false }
arrow-select = { version = ">=59, <61", default-features = false }
4 changes: 4 additions & 0 deletions rust/ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,9 @@ adbc_core.workspace = true
arrow-array.workspace = true
arrow-schema.workspace = true

[dev-dependencies]
arrow-buffer.workspace = true
arrow-data.workspace = true

[package.metadata.docs.rs]
all-features = true
49 changes: 49 additions & 0 deletions rust/ffi/src/driver_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2079,6 +2079,55 @@ mod tests {
use crate::types::FFI_AdbcErrorV100;
use std::ptr::{null, null_mut};

/// Drivers may export buffers that only meet the C Data Interface's
/// recommended 8-byte alignment, while arrow-rs requires 16 bytes for
/// i128. Importing such data must realign it instead of panicking.
/// See https://github.com/apache/arrow-adbc/issues/2526.
#[test]
fn test_import_under_aligned_buffers() {
use arrow_array::{Array, Decimal128Array, RecordBatch};
use arrow_buffer::Buffer;
use arrow_data::ArrayData;
use arrow_schema::{Field, Fields};

let decimal_type = DataType::Decimal128(10, 2);
let aligned = Buffer::from_vec(vec![0_i128, 1, 2]);
let under_aligned = aligned.slice(8);
assert_eq!(under_aligned.as_ptr().align_offset(8), 0);
assert_ne!(under_aligned.as_ptr().align_offset(16), 0);

let child = unsafe {
ArrayData::builder(decimal_type.clone())
.len(2)
.add_buffer(under_aligned)
.build_unchecked()
};
let struct_type =
DataType::Struct(Fields::from(vec![Field::new("d", decimal_type, false)]));
let data = unsafe {
ArrayData::builder(struct_type.clone())
.len(2)
.add_child_data(child)
.build_unchecked()
};

// Same import path as `statement_bind`; `ArrowArrayStreamReader`
// (used by `statement_bind_stream` and the driver manager) goes
// through `from_ffi_and_data_type`, which aligns the same way.
let schema = FFI_ArrowSchema::try_from(&struct_type).unwrap();
let imported = unsafe { from_ffi(FFI_ArrowArray::new(&data), &schema) }.unwrap();
let batch = RecordBatch::from(StructArray::from(imported));

let column = batch
.column(0)
.as_any()
.downcast_ref::<Decimal128Array>()
.unwrap();
assert_eq!(column.values().inner().as_ptr().align_offset(16), 0);
assert_eq!(column.value(0), 1_i128 << 64);
assert_eq!(column.value(1), 2_i128 << 64);
}

#[test]
fn test_error_details_null() {
unsafe {
Expand Down
Loading