vortex_array/stream/
mod.rs

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