Skip to content

[WIP] feat(rust): Let the returned RecordBatchReader outlive & parameters #2693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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: 2 additions & 2 deletions rust/core/src/driver_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,15 +826,15 @@ impl Connection for ManagedConnection {
Ok(reader)
}

fn get_objects(
fn get_objects<'a>(
&self,
depth: crate::options::ObjectDepth,
catalog: Option<&str>,
db_schema: Option<&str>,
table_name: Option<&str>,
table_type: Option<Vec<&str>>,
column_name: Option<&str>,
) -> Result<impl RecordBatchReader> {
) -> Result<impl RecordBatchReader + 'a> {
let catalog = catalog.map(CString::new).transpose()?;
let db_schema = db_schema.map(CString::new).transpose()?;
let table_name = table_name.map(CString::new).transpose()?;
Expand Down
16 changes: 8 additions & 8 deletions rust/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,15 @@ pub trait Connection: Optionable<Option = OptionConnection> {
/// | fk_table | utf8 not null |
/// | fk_column_name | utf8 not null |
///
fn get_objects(
&self,
fn get_objects<'a>(
&'_ self,
depth: options::ObjectDepth,
catalog: Option<&str>,
db_schema: Option<&str>,
table_name: Option<&str>,
table_type: Option<Vec<&str>>,
column_name: Option<&str>,
) -> Result<impl RecordBatchReader + Send>;
catalog: Option<&'_ str>,
db_schema: Option<&'_ str>,
table_name: Option<&'_ str>,
table_type: Option<Vec<&'_ str>>,
column_name: Option<&'_ str>,
) -> Result<impl RecordBatchReader + Send + 'a>;

/// Get the Arrow schema of a table.
///
Expand Down
16 changes: 8 additions & 8 deletions rust/driver/datafusion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,15 +725,15 @@ impl Connection for DataFusionConnection {
Ok(reader)
}

fn get_objects(
&self,
fn get_objects<'a>(
&'_ self,
depth: adbc_core::options::ObjectDepth,
_catalog: Option<&str>,
_db_schema: Option<&str>,
_table_name: Option<&str>,
_table_type: Option<Vec<&str>>,
_column_name: Option<&str>,
) -> Result<impl RecordBatchReader + Send> {
_catalog: Option<&'_ str>,
_db_schema: Option<&'_ str>,
_table_name: Option<&'_ str>,
_table_type: Option<Vec<&'_ str>>,
_column_name: Option<&'_ str>,
) -> Result<impl RecordBatchReader + Send + 'a> {
let batch = GetObjectsBuilder::new().build(&self.runtime, &self.ctx, &depth)?;
let reader = SingleBatchReader::new(batch);
Ok(reader)
Expand Down
16 changes: 8 additions & 8 deletions rust/driver/dummy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,15 @@ impl Connection for DummyConnection {
Ok(reader)
}

fn get_objects(
&self,
fn get_objects<'a>(
&'_ self,
_depth: ObjectDepth,
_catalog: Option<&str>,
_db_schema: Option<&str>,
_table_name: Option<&str>,
_table_type: Option<Vec<&str>>,
_column_name: Option<&str>,
) -> Result<impl RecordBatchReader> {
_catalog: Option<&'_ str>,
_db_schema: Option<&'_ str>,
_table_name: Option<&'_ str>,
_table_type: Option<Vec<&'_ str>>,
_column_name: Option<&'_ str>,
) -> Result<impl RecordBatchReader + 'a> {
let constraint_column_usage_array_inner = StructArray::from(vec![
(
Arc::new(Field::new("fk_catalog", DataType::Utf8, true)),
Expand Down
44 changes: 44 additions & 0 deletions rust/driver/dummy/tests/driver_exporter_dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use arrow_select::concat::concat_batches;
use adbc_core::driver_manager::{
ManagedConnection, ManagedDatabase, ManagedDriver, ManagedStatement,
};
use adbc_core::error::Result;
use adbc_core::options::{
AdbcVersion, InfoCode, IngestMode, IsolationLevel, ObjectDepth, OptionConnection,
OptionDatabase, OptionStatement,
Expand Down Expand Up @@ -475,6 +476,49 @@ fn test_connection_get_objects() {
);
}

struct BoxedReaderConnection(DummyConnection);

impl BoxedReaderConnection {
pub fn get_objects<'a>(
&'_ self,
depth: ObjectDepth,
catalog: Option<&'_ str>,
db_schema: Option<&'_ str>,
table_name: Option<&'_ str>,
table_type: Option<Vec<&'_ str>>,
column_name: Option<&'_ str>,
) -> Result<Box<dyn RecordBatchReader + Send>> {
let reader = self.0.get_objects(
depth,
catalog,
db_schema,
table_name,
table_type,
column_name,
)?;
let boxed_reader = Box::new(reader);
Ok(boxed_reader)
}
}

#[test]
fn test_connection_get_objects_as_boxed_reader() {
let mut driver = DummyDriver {};
let mut database = driver.new_database().unwrap();
let connection = database.new_connection().unwrap();
let boxed_connection = BoxedReaderConnection(connection);
let _boxed_reader: Box<dyn RecordBatchReader> = boxed_connection
.get_objects(
ObjectDepth::All,
None,
None,
None,
Some(vec!["table", "view"]),
None,
)
.unwrap();
}

// Statement

#[test]
Expand Down
16 changes: 8 additions & 8 deletions rust/driver/snowflake/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ impl adbc_core::Connection for Connection {
self.0.get_info(codes)
}

fn get_objects(
&self,
fn get_objects<'a>(
&'_ self,
depth: adbc_core::options::ObjectDepth,
catalog: Option<&str>,
db_schema: Option<&str>,
table_name: Option<&str>,
table_type: Option<Vec<&str>>,
column_name: Option<&str>,
) -> Result<impl RecordBatchReader + Send> {
catalog: Option<&'_ str>,
db_schema: Option<&'_ str>,
table_name: Option<&'_ str>,
table_type: Option<Vec<&'_ str>>,
column_name: Option<&'_ str>,
) -> Result<impl RecordBatchReader + Send + 'a> {
self.0.get_objects(
depth,
catalog,
Expand Down
Loading