Skip to content

Commit f4f2deb

Browse files
committed
changes: re-export non_blocking mod, blocking mod for sync traits, add sync wrappers
Signed-off-by: if0ne <[email protected]>
1 parent 16fbae9 commit f4f2deb

File tree

19 files changed

+892
-849
lines changed

19 files changed

+892
-849
lines changed

rust/core/src/blocking.rs

Lines changed: 793 additions & 0 deletions
Large diffs are not rendered by default.

rust/core/src/executor.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
use std::{fmt::Debug, future::Future};
19+
20+
pub trait AsyncExecutor: Sized {
21+
type Config: Default;
22+
type Error: Debug;
23+
24+
fn new(config: Self::Config) -> Result<Self, Self::Error>;
25+
fn block_on<F: Future>(&self, future: F) -> F::Output;
26+
}

rust/core/src/lib.rs

Lines changed: 3 additions & 464 deletions
Large diffs are not rendered by default.

rust/core/src/non_blocking.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,21 @@ use std::collections::HashSet;
2222

2323
use crate::error::Result;
2424
use crate::options::{self, *};
25-
use crate::PartitionedResult;
25+
26+
/// Each data partition is described by an opaque byte array and can be
27+
/// retrieved with [Connection::read_partition].
28+
pub type Partitions = Vec<Vec<u8>>;
29+
30+
/// A partitioned result set as returned by [Statement::execute_partitions].
31+
#[derive(Debug, PartialEq, Eq)]
32+
pub struct PartitionedResult {
33+
/// The result partitions.
34+
pub partitions: Partitions,
35+
/// The schema of the result set.
36+
pub schema: Schema,
37+
/// The number of rows affected if known, else -1.
38+
pub rows_affected: i64,
39+
}
2640

2741
/// Ability to configure an object by setting/getting options.
2842
#[trait_variant::make(AsyncOptionable: Send)]
@@ -362,7 +376,10 @@ pub trait LocalAsyncConnection: LocalAsyncOptionable<Option = OptionConnection>
362376
/// # Arguments
363377
///
364378
/// - `partition` - The partition descriptor.
365-
async fn read_partition(&self, partition: &[u8]) -> Result<impl RecordBatchReader + Send>;
379+
async fn read_partition(
380+
&self,
381+
partition: &[u8],
382+
) -> Result<impl RecordBatchReader + Send + 'static>;
366383
}
367384

368385
/// A handle to an async ADBC statement.

rust/driver/datafusion/src/lib.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
// under the License.
1717
#![allow(refining_impl_trait)]
1818

19-
mod syncify;
20-
19+
use adbc_core::executor::AsyncExecutor;
2120
use adbc_core::non_blocking::{
2221
AsyncConnection, AsyncDatabase, AsyncDriver, AsyncStatement, LocalAsyncOptionable,
2322
};
@@ -950,5 +949,26 @@ impl AsyncStatement for DataFusionStatement {
950949
}
951950
}
952951

952+
pub struct TokioRuntime(tokio::runtime::Runtime);
953+
954+
impl AsyncExecutor for TokioRuntime {
955+
type Config = ();
956+
type Error = std::io::Error;
957+
958+
fn new(_: Self::Config) -> std::result::Result<Self, Self::Error> {
959+
tokio::runtime::Builder::new_multi_thread()
960+
.enable_all()
961+
.build()
962+
.map(TokioRuntime)
963+
}
964+
965+
fn block_on<F: Future>(&self, future: F) -> F::Output {
966+
self.0.block_on(future)
967+
}
968+
}
969+
953970
#[cfg(feature = "ffi")]
954-
adbc_ffi::export_driver!(DataFusionDriverInit, crate::syncify::SyncDataFusionDriver);
971+
adbc_ffi::export_driver!(
972+
DataFusionDriverInit,
973+
adbc_core::blocking::SyncDriverWrapper::<TokioRuntime, DataFusionDriver>
974+
);

0 commit comments

Comments
 (0)