vortex_array/stream/
mod.rs

1use std::pin::Pin;
2
3pub use adapter::*;
4pub use ext::*;
5use futures_util::{Stream, stream};
6use vortex_dtype::DType;
7use vortex_error::VortexResult;
8
9use crate::{Array, ArrayRef};
10
11mod adapter;
12mod ext;
13
14/// A stream of array chunks along with a DType.
15///
16/// Can be thought of as equivalent to Arrow's RecordBatchReader.
17pub trait ArrayStream: Stream<Item = VortexResult<ArrayRef>> {
18    fn dtype(&self) -> &DType;
19}
20
21/// Trait for a [`Stream`] of [`ArrayRef`]s that can be passed between threads.
22pub type SendableArrayStream = Pin<Box<dyn ArrayStream + Send>>;
23
24impl ArrayStream for SendableArrayStream {
25    fn dtype(&self) -> &DType {
26        (**self).dtype()
27    }
28}
29
30impl dyn Array + '_ {
31    /// Create an [`ArrayStream`] over the array.
32    pub fn to_array_stream(&self) -> impl ArrayStream + 'static {
33        ArrayStreamAdapter::new(self.dtype().clone(), stream::iter(self.to_array_iterator()))
34    }
35}