pub struct RecordBatchReceiverStreamBuilder { /* private fields */ }
Expand description

Builder for RecordBatchReceiverStream that propagates errors and panic’s correctly.

RecordBatchReceiverStreamBuilder is used to spawn one or more tasks that produce RecordBatches and send them to a single Receiver which can improve parallelism.

This also handles propagating panic`s and canceling the tasks.

§Example

The following example spawns 2 tasks that will write RecordBatches to the tx end of the builder, after building the stream, we can receive those batches with calling .next()

let schema = Arc::new(Schema::new(vec![Field::new("foo", DataType::Int8, false)]));
let mut builder = RecordBatchReceiverStreamBuilder::new(Arc::clone(&schema), 10);

// task 1
let tx_1 = builder.tx();
let schema_1 = Arc::clone(&schema);
builder.spawn(async move {
    // Your task needs to send batches to the tx
    tx_1.send(Ok(RecordBatch::new_empty(schema_1))).await.unwrap();

    Ok(())
});

// task 2
let tx_2 = builder.tx();
let schema_2 = Arc::clone(&schema);
builder.spawn(async move {
    // Your task needs to send batches to the tx
    tx_2.send(Ok(RecordBatch::new_empty(schema_2))).await.unwrap();

    Ok(())
});

let mut stream = builder.build();
while let Some(res_batch) = stream.next().await {
    // `res_batch` can either from task 1 or 2

    // do something with `res_batch`
}

Implementations§

source§

impl RecordBatchReceiverStreamBuilder

source

pub fn new(schema: SchemaRef, capacity: usize) -> Self

create new channels with the specified buffer size

source

pub fn tx(&self) -> Sender<Result<RecordBatch>>

Get a handle for sending RecordBatch to the output

source

pub fn spawn<F>(&mut self, task: F)
where F: Future<Output = Result<()>> + Send + 'static,

Spawn task that will be aborted if this builder (or the stream built from it) are dropped

This is often used to spawn tasks that write to the sender retrieved from Self::tx, for examples, see the document of this type.

source

pub fn spawn_blocking<F>(&mut self, f: F)
where F: FnOnce() -> Result<()> + Send + 'static,

Spawn a blocking task that will be aborted if this builder (or the stream built from it) are dropped

This is often used to spawn tasks that write to the sender retrieved from Self::tx, for examples, see the document of this type.

source

pub fn build(self) -> SendableRecordBatchStream

Create a stream of all RecordBatch written to tx

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V